Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf doesn't work #86

Closed
winston0410 opened this issue Aug 2, 2022 · 2 comments
Closed

allOf doesn't work #86

winston0410 opened this issue Aug 2, 2022 · 2 comments

Comments

@winston0410
Copy link

Not quite sure how to reproduce this in a useful way, I have a schema like this, which extends a schema in allOf. Even though I have ensure that the accept exists in header in programmatic level, it is not reflected in the type generated by this library.

import { FromSchema } from "json-schema-to-ts";

const defHeaderSchema = {
	type: "object",
	properties: {
		header: {
			properties: {
				accept: {
					type: "string",
					pattern: "application/(?:\\*|json)|\\*/\\*"
				}
			},
			required: ["accept"]
		}
	},
} as const

const postSchema = {
	allOf: [ defHeaderSchema ],
	type: "object",
	properties: {
		body: {
			type: "object",
			properties: {
				number: {
					type: "string"
				},
			},
			required: ["number"]
		}
	}
} as const;

let obj!: FromSchema<typeof postSchema>

See the final type by hovering on obj

@ThomasAribart
Copy link
Owner

Hi @winston0410 ! See #79 : Your header schema misses a type: "object" keyword !

@winston0410
Copy link
Author

Right after adding that back in, the type is generated perfectly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants