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

[gen] adding support for "Any" and "AnyObject" as json in codegen #3205

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hochgi
Copy link
Contributor

@hochgi hochgi commented Nov 12, 2024

/fixes #3199
/claim #3199

@@ -1077,7 +1078,10 @@ final case class EndpointGen(config: Config) {
),
)
case JsonSchema.Null => throw new Exception("Null query parameters are not supported")
case JsonSchema.AnyJson => throw new Exception("AnyJson query parameters are not supported")
case JsonSchema.AnyJson => {
// throw new Exception("AnyJson query parameters are not supported")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why did we previously throw exception?
Am I breaking some other validation now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@987Nabil any idea regarding this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Please no {} block for a case handling :)
  2. The exception was that there is no handling implemented. Not that there can't be one
  3. None seems odd. Can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. sure, will do
  2. the exception refers to query parameters, so that was weiird.
  3. the method is def schemaToCode(…): Option[Code.File], there is no need to generate a file for Json. It's just an import. So None was obvious to me.

eats: {}
extra_attributes:
type: object
additionalProperties: true
Copy link
Contributor Author

@hochgi hochgi Nov 12, 2024

Choose a reason for hiding this comment

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

should also test for all the 3 out of 4 possible cases we handle?

  extra_attributes:
    type: object
    additionalProperties: true

  extra_attributes:
    type: object
    additionalProperties: {}

  extra_attributes:
    additionalProperties: true

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, help me out. This dynamic fields open api always confuses me

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 straight out of the docs:
Screenshot 2024-12-02 at 17 05 06

@@ -1077,7 +1078,10 @@ final case class EndpointGen(config: Config) {
),
)
case JsonSchema.Null => throw new Exception("Null query parameters are not supported")
case JsonSchema.AnyJson => throw new Exception("AnyJson query parameters are not supported")
case JsonSchema.AnyJson => {
// throw new Exception("AnyJson query parameters are not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Please no {} block for a case handling :)
  2. The exception was that there is no handling implemented. Not that there can't be one
  3. None seems odd. Can you explain?

eats: {}
extra_attributes:
type: object
additionalProperties: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, help me out. This dynamic fields open api always confuses me

MetaData.KeySchema(
fromSerializableSchema(keySchema),

val definedAttributesCount = schema.productIterator.count(_.asInstanceOf[Option[_]].isDefined)
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I learned from the zio http open api integration: I hate it and open API is a crap format haha 😂

@hochgi hochgi force-pushed the gen-issue-3199-support-any-and-any-object-as-json branch from afe0bce to 2640057 Compare December 2, 2024 15:12
@hochgi hochgi requested a review from 987Nabil December 2, 2024 15:13
  extra_attributes:
    type: object
    additionalProperties: true

  extra_attributes:
    type: object
    additionalProperties: {}

  extra_attributes:
    additionalProperties: true

but fails for this case, which might not be an issue (or an issue with zio-schema):

  extra_attributes:
    additionalProperties: {}
@hochgi hochgi force-pushed the gen-issue-3199-support-any-and-any-object-as-json branch from 7007e5c to feedb58 Compare December 14, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gen] accept OpenAPI "open" types like "any" & "anyObject"
2 participants