Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Can the schema created by combining versioned schemas have proper type? #250

Open
bahmutov opened this issue Mar 25, 2019 · 1 comment
Open
Labels
enhancement New feature or request question Further information is requested

Comments

@bahmutov
Copy link
Contributor

If we create a new schema by adding objects, we should have a good type of the result, which will allow us to know the available schemas and their versions statically. This would provide a great IntelliSense for commands and assertions.

For example, in https://github.com/bahmutov/todo-api-with-json-schema/blob/master/schemas/index.ts we know both schemas

export const schemas: SchemaCollection = combineSchemas(
  PostTodoRequest,
  PostTodoResponse
)

So when we access schemas, we should statically know that only PostTodoRequest and PostTodoResponse are valid properties

Related look ups
https://mariusschulz.com/blog/typescript-2-1-keyof-and-lookup-types

@bahmutov bahmutov added enhancement New feature or request question Further information is requested labels Mar 25, 2019
@bahmutov
Copy link
Contributor Author

Probably in utils.ts

export const combineSchemas = (...versioned: VersionedSchema[]) => {
  const result: SchemaCollection = {}
  versioned.forEach(v => {
    const title = v[Object.keys(v)[0]].schema.title
    const name = normalizeName(title)
    result[name] = v
  })
  return result
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant