astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
734 stars 82 forks source link

With both allOf and properties in a schema, the properties are omitted #240

Closed briandiephuis closed 10 months ago

briandiephuis commented 10 months ago

Describe the bug When an API describes both allOf and properties on a Swagger schema the properties are not included in the generated Zod schema.

Minimal reproduction See this Playground example.

TestResult defines both an allOf (line 34) and properties (line 39). However, the clientId property is not available in the api.client.ts anywhere.

Expected behavior To have an extended schema, something like:

const TestResult = ResultBase.extend({
  clientId: z.number().int(),
});

Additional context I'm pretty new with Swagger, not sure if having both an allOf reference and properties is considered an anti-pattern, if so, please let me know so I can talk to the company that build this API 😉 .

The API is build with the C# minimal-api with these settings:

builder.Services.AddSwaggerGen(o => {
    var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    o.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));

    o.SupportNonNullableReferenceTypes();
    o.UseAllOfForInheritance();
    o.UseAllOfToExtendReferenceSchemas();
});
briandiephuis commented 10 months ago

Nevermind, they removed the o.UseAllOfForInheritance(); option and now all is working as expected 🤷