Skip to content

Fixed openapi 3 spec to default additionalProperties to true #585

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

Merged
merged 1 commit into from
May 7, 2021
Merged

Fixed openapi 3 spec to default additionalProperties to true #585

merged 1 commit into from
May 7, 2021

Conversation

mehalter
Copy link
Contributor

@mehalter mehalter commented May 5, 2021

Resolves #583 . Let me know if this seems correct or if you have any comments/critiques!

Signed-off-by: Micah Halter [email protected]

@drwpow
Copy link
Contributor

drwpow commented May 7, 2021

Reasoning makes sense! All on board for generating types that follow the spec. This looks great!

@@ -26,6 +26,7 @@ describe("transformPathsObj", () => {
schema: {
type: "object",
properties: { title: { type: "string" }, body: { type: "string" } },
additionalProperties: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came here to check if you had an additionalProperties: false test, and you did! Great work 🙂

@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #585 (2300c9b) into main (a36a728) will increase coverage by 1.07%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #585      +/-   ##
==========================================
+ Coverage   88.53%   89.61%   +1.07%     
==========================================
  Files           9        9              
  Lines         349      366      +17     
  Branches      123      134      +11     
==========================================
+ Hits          309      328      +19     
- Misses         37       38       +1     
+ Partials        3        0       -3     
Impacted Files Coverage Δ
src/transform/headers.ts 25.00% <0.00%> (-2.28%) ⬇️
src/transform/index.ts 83.92% <ø> (+4.29%) ⬆️
src/transform/responses.ts 88.37% <ø> (+0.27%) ⬆️
src/transform/operation.ts 97.05% <100.00%> (+0.18%) ⬆️
src/transform/parameters.ts 97.56% <100.00%> (+0.06%) ⬆️
src/transform/schema.ts 98.68% <100.00%> (+1.62%) ⬆️
src/transform/paths.ts 92.30% <0.00%> (+0.30%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c51afc...2300c9b. Read the comment docs.

@mehalter
Copy link
Contributor Author

mehalter commented May 7, 2021

Ah I forgot to run the linter, let me do that to fix this test.

@mehalter
Copy link
Contributor Author

mehalter commented May 7, 2021

@drwpow updated the commit with linted code

@mehalter mehalter requested a review from drwpow May 7, 2021 15:12
@drwpow drwpow merged commit 587d5d3 into openapi-ts:main May 7, 2021
@drwpow
Copy link
Contributor

drwpow commented May 7, 2021

@all-contributors please add @mehalter for code, test, bug

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @mehalter! 🎉

@drwpow
Copy link
Contributor

drwpow commented May 7, 2021

Released in v3.2.4! 🎉

@radist2s
Copy link
Contributor

@mehalter, @drwpow,
seems, this release broke a lot of specifications that were already working.
According to OpenAPI v 3.0.2: Consistent with JSON Schema, additionalProperties defaults to true.
At the same time, according to 3.0.1 additionalProperties is optional.

By the way with oneOf generated result could be useless with non object types:

{
  "pictures": {
    "type": "array",
    "items": {
      "oneOf": [
        {
          "type": "integer"
        },
        {
          "$ref": "#/components/schemas/ItemsArtworksPictures"
        }
      ]
    }
  }
}
{
  pictures?: ((number | components["schemas"]["ItemsArtworksPictures"]) & {
    [key: string]: any;
  })[];
}

@drwpow
Copy link
Contributor

drwpow commented May 25, 2021

Due to feedback, we’re going to revert this behavior in 3.3.0, back to the way it was. However, you can get this behavior by opting in via the --additional-properties flag. So if you need that, simply add that flag (it’ll be a Node.js API option, too)!

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

Successfully merging this pull request may close these issues.

additionalProperties is not correctly defaulted to true
3 participants