-
-
Notifications
You must be signed in to change notification settings - Fork 528
fix: Correct handling of default parameter values in referenced component schema #1746
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
Conversation
🦋 Changeset detectedLatest commit: dd618c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Ah, I usually use eslint + prettier for code styling, and I haven't used biome to enforce code style. There seems to be a bug with the biome plugin on my VSCode, causing multiple failures in code style checks.😭 |
I think this change is insufficient since Unless a field is explicitly marked Consider this simple schema where a single component schema is used as both the request body and as the response.
Since only a single type definition will be created for paths:
/purchase:
post:
requestBody:
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/ShirtPurchase'
responses:
'200':
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/ShirtPurchase'
components:
schemas:
ShirtPurchase:
type: object
properties:
color:
type: string
enum:
- blue
- yellow
quantity:
type: number
minimum: 1
default: 1
required:
- color |
Ah sorry—yeah that was kind of a silent change. But I’ve been blown away with the bugfixes Biome had in lots of ESLint packages, and the speed is hard to beat. Plus the team is really collaborative and I’m finding contributing to Biome easier than ESLint! But formatting-wise I’m neutral on Prettier vs Biome for formatting; that was more an experiment. the As I type all this out, this is probably all good info that I should put into the CONTRIBUTING.md guide 🙂 |
Alright, I think I should learn more about Biome too!😊 |
Oh! It seems I did overlook this situation. I'm curious, what approach do you have for handling this kind of situation? @duncanbeevers @drwpow |
My suggestion is to not use the presence of |
+1 to @duncanbeevers’ comment. For fixing this, I usually start by creating a failing test (TDD), and the one they supplied seems sufficient! From there, tracing/resolving nodes in 7.x is one of the major internal reasons for rewriting! In previous versions it was much harder to peer into nodes. But in the current version, It does add a little bit of work (especially considering nested |
I noticed that @duncanbeevers' proposed approach conflicts with #1681, so maybe we should consider again here.@drwpow |
That doesn't seem like a conflict. My proposal is to make these fields optional, which seems to align with what is happening in that PR as well. I'm happy to stand corrected if I'm misunderstanding. |
I discovered that this default behavior can be controlled through defaultNonNullable. By setting it to false, the scenario mentioned in this PR can be accommodated. It seems designed this way to meet the needs of different users. Or do we need to handle the requestBody separately?If I am misunderstanding, please correct me. |
@phk422 Thanks for calling out that I think that makes this PR the correct approach since it detects these |
Above, I think this pr can be merged,@drwpow, what do you think? |
I think so! If you could add a |
…nent schema (openapi-ts#1746) * fix: Correct handling of default parameter values in referenced component schema * chore: lint code * chore: lint code * Create dull-birds-pump.md
Hello, I still have the same issue with this OpenAPi spec: https://docs-be.here.com/bundle/tour-planning-api-api-reference/page/api.yaml (using The field priority:
maximum: 2
minimum: 1
type: integer
description: |
Specifies the priority of the job with 1 for high priority jobs and 2 for normal jobs.
example: 2
default: 2 |
@Nikoms When I run the types-generator on this OpenAPI document i see the expected behavior.
|
Ok then, I must have a problem with my computer or something, because I have this:
Note: I also tried with I'm on macos, using node |
I can confirm this is still a problem.
My guess is that the option (which should default to false) somehow gets overridden somewhere to be true once a $ref is followed, and then explicitly setting the flag to be false in the command seems to force it to remain false properly. |
This option is now defaulting to true in v7, sorry I didn't realise that. I'm guessing @duncanbeevers is on v6. |
fix: Correct handling of default parameter values in referenced component schema
Changes
Fix #1741
How to Review
Tests added; tests should pass
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)