Skip to content

Commit

Permalink
Fix: Required array not respecting encodedName (#2906)
Browse files Browse the repository at this point in the history
The required array didn't make use the encoded name creating invalid
spec where there would be a mismatch of names
  • Loading branch information
timotheeguerin authored Feb 12, 2024
1 parent 0b0c70e commit 4915d5b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-brooms-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@typespec/openapi3": patch
---

Fix: `required` array on schema wasn't using the value provided by `@encodedName("application/json"`
8 changes: 7 additions & 1 deletion packages/openapi3/src/schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter<
}

if (!this.#metadataInfo.isOptional(prop, visibility)) {
requiredProps.push(prop.name);
const encodedName = resolveEncodedName(
this.emitter.getProgram(),
prop,
this.#getContentType()
);

requiredProps.push(encodedName);
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/openapi3/test/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("openapi3: models", () => {
);

expect(res.schemas.Foo).toMatchObject({
required: ["xJson"],
properties: {
xJson: { type: "integer", format: "int32" },
},
Expand All @@ -48,6 +49,7 @@ describe("openapi3: models", () => {
);

expect(res.schemas.Foo).toMatchObject({
required: ["xJson"],
properties: {
xJson: { type: "integer", format: "int32" },
},
Expand All @@ -65,6 +67,7 @@ describe("openapi3: models", () => {
);

expect(res.schemas.Foo).toMatchObject({
required: ["xJson"],
properties: {
xJson: { type: "integer", format: "int32" },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ components:
WithEncodedNames:
type: object
required:
- notBefore
- expires
- nbf
- exp
- created
- updated
properties:
Expand Down

0 comments on commit 4915d5b

Please sign in to comment.