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

chore: fix OasSchema types #1362

Merged
merged 3 commits into from
Jan 18, 2024
Merged

chore: fix OasSchema types #1362

merged 3 commits into from
Jan 18, 2024

Conversation

vladkens
Copy link
Contributor

@vladkens vladkens commented Dec 16, 2023

What/Why/How?

Fix wrong typing for Oas3_1Schema.

When using type in TypeScript instead of interface, need to omit all overridden fields first.

type A = { type: string }
type B = A & { type: string | string[] }
const b: B = { type: ["string", "number"] } // typescript say error here

// so it should be
type C = Omit<A, "type"> & { type: string | string[] }
const c: C = { type: ["string", "number"] } // no problem now

Reference

https://www.typescriptlang.org/play?ssl=7&ssc=62&pln=1&pc=1#code/C4TwDgpgBAglC8UDeVSQFxQM7AE4EsA7AcygF8AoNaAIQVigDJlVwJMcCSoAfbPIsQDaAXXIUAxgHtCOKACNMdRCmqYhAIk6CNAGigbCAVwC28iLg1iyUAPS3WkLBIJhg2AIYgoF3FNxQABYWEBQU9thSUPjuWIFSRgA2ACYKodRQAML0APImMQA8MPoa1BoAfEwsavxcpHzaJKLi0rLuEpjZKo7sUJqNxHoGxmYWVuR2DoRRYH7yiRAmUNMA7kA

Testing

Screenshots (optional)

Check yourself

  • Code is linted
  • Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@vladkens vladkens requested a review from a team as a code owner December 16, 2023 00:52
Copy link

changeset-bot bot commented Dec 16, 2023

⚠️ No Changeset found

Latest commit: bc00b32

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tatomyr
Copy link
Contributor

tatomyr commented Dec 19, 2023

Thanks for pointing this out, @vladkens!

I'd suggest using interface instead. I'm unsure of the initial reason for using the type. Moreover, there are more properties to cover here: properties, additionalProperties, items, allOf &c. - all of them should also be Oas3_1Schema instead of Oas3Schema. Don't you mind tackling that as well?

@lornajane
Copy link
Contributor

@tatomyr I see that you asked for further changes on this pull request. Can the existing changes be reviewed as they are, or do your requested updates also need to be included to make it useful?

@tatomyr
Copy link
Contributor

tatomyr commented Jan 16, 2024

@lornajane for me it makes sense to do everything in one MR. If @vladkens won't respond, I'll make a separate update instead of this one once I have time.

@vladkens
Copy link
Contributor Author

Hi, @tatomyr. Didn't see the notification in time.

Fixed nested typing too and made Oas3_1Schema as interface. Also put the general properties for v3 & v3.1 in a separate internal interface.

Please re-view PR.

From my side checked with:

npm run lint
npm run typecheck
npm run prettier:check

@tatomyr
Copy link
Contributor

tatomyr commented Jan 17, 2024

Thank you @vladkens very much for handling all the comments! I'll review and merge your PR soon.

@tatomyr tatomyr changed the title Fix Oas3_1Schema type chore: fix OasSchema types Jan 17, 2024
Copy link
Contributor

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you again for your efforts @vladkens!
The changes will be available in the next release.

@tatomyr tatomyr merged commit 63aba31 into Redocly:main Jan 18, 2024
26 checks passed
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.

3 participants