Skip to content

If no type is specified, type as unknown #1049

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 6 commits into from
Apr 7, 2023

Conversation

mitchell-merry
Copy link
Contributor

@mitchell-merry mitchell-merry commented Mar 12, 2023

Changes

Fixes #1039.

How to Review

Related docs: https://swagger.io/docs/specification/data-models/data-types/#any

I wish I could just update the snapshots without updating the specs.

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

@drwpow
Copy link
Contributor

drwpow commented Apr 5, 2023

Thanks so much for doing the work on this, but I believe this conflicts with #1032 and the --empty-objects-unknown flag. I also gave some additional context here. But please let me know if I’m mistaken.

@drwpow drwpow closed this Apr 5, 2023
@mitchell-merry
Copy link
Contributor Author

mitchell-merry commented Apr 5, 2023

It doesn't conflict with that PR, since this is specifically when type is not specified. (I interpret that PR to define the behavior for type: object). I've left my comments on that issue.

@drwpow drwpow reopened this Apr 5, 2023
@drwpow
Copy link
Contributor

drwpow commented Apr 5, 2023

My mistake. I agree this is a good change. Sorry for the misunderstanding on my part! If the merge conflicts are fixed I’m happy to merge this and agree this is a bugfix and not a breaking change.

@mitchell-merry
Copy link
Contributor Author

Awesome, thank you! Will do once I get a chance

@@ -18,4 +19,26 @@ describe("utils", () => {
return expect(tsUnionOf(...[0, true, "string", '"hello"'])).toBe('0 | true | string | "hello"');
});
});

describe("tsIntersectionOf", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I happened to also add a utils.test.ts before this one made it into main :D but our test cases use different approaches. Would you like me to convert my cases into the pre-existing ones?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the opposite—we can move the ones there into this one. Thanks for adding these!

@@ -3483,7 +3483,7 @@ export interface external {
* @example Sammy Shark
*/
user_name?: string;
user_billing_address?: Record<string, never> & external["resources/billing/models/billing_address.yml"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an intentional change - since unknown & AnyType === AnyType is a tautology, I've added code to tsIntersectionOf to remove these redundant bits of the intersection.

These extraneous unknowns are caused by the definitions in the schema:

user_billing_address:
  allOf:
    - description: some description
    - $ref: 'billing_address.yml'

We (correctly) interpret this as two schemas, the first registers to be a schema with no type defined and therefore unknown. Why they did this escapes me.

@mitchell-merry mitchell-merry mentioned this pull request Apr 6, 2023
3 tasks
Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@drwpow drwpow merged commit 6408fa6 into openapi-ts:main Apr 7, 2023
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.

Property without type should be declared as unknown
2 participants