Skip to content

Conversation

numbata
Copy link
Collaborator

@numbata numbata commented Jan 28, 2025

Improves the handling of unconventional entity class names and enhances support for diverse types in Swagger documentation generation.

Changes

  • Fixed ambiguous_model_type? to correctly identify entities with non-standard class names.
  • Introduced primitive_type? for clearer handling of primitives and additional non-class types (string, array).
  • Enabled support for custom type parsers to handle registered types for parsing.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Looks great. Can I OCD over a nit please? Sorry!

expose :nested, using: TheseApi::Entities::Nested, documentation: { desc: 'Nested object.' }
expose :nested_child, using: TheseApi::Entities::NestedChild, documentation: { desc: 'Nested child object.' }
expose :polymorphic, using: TheseApi::Entities::Polymorphic, documentation: { desc: 'Polymorphic Model' }
expose :mixed, using: TheseApi::Entities::MixedType, documentation: { desc: 'A model with mix of types' }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expose :mixed, using: TheseApi::Entities::MixedType, documentation: { desc: 'A model with mix of types' }
expose :mixed, using: TheseApi::Entities::MixedType, documentation: { desc: 'A model with mix of types.' }

(and let's replace Polymorphic Model with A polymorphic model. above, to be consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done here: 47e6140

@numbata
Copy link
Collaborator Author

numbata commented Jan 28, 2025

Can I OCD over a nit please?

Of course! All suggestions are always welcome.

strategy:
fail-fast: false
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3']
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm.. Maybe instead of removing ruby 3.0, the specific grape version can be set instead. As a separate PR ofc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That's a good idea, will merge this one, feel free to pick it up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Will do this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As promised: #76

@dblock dblock merged commit 0c1af79 into ruby-grape:master Jan 30, 2025
5 checks passed
krororo added a commit to krororo/grape-swagger-entity that referenced this pull request Apr 28, 2025
This commit fixes an issue where specifying a class like `Time`
for the `type` option in `expose` documentation resulted in an error
instead of generating the correct Swagger/OpenAPI specification.

This functionality was working correctly in v0.5.5 but regressed
after PR ruby-grape#75, leading to the following error:

```
GrapeSwagger::Errors::UnregisteredParser:
  No parser registered for Time.
```

The `primitive_type?` method now uses
`GrapeSwagger::DocMethods::DataType.call` to resolve the type
name before checking if it's a primitive type.
This ensures that types like `Time` are correctly identified as
strings with the `date-time` format, restoring the previous behavior.
krororo added a commit to krororo/grape-swagger-entity that referenced this pull request Apr 28, 2025
This commit fixes an issue where specifying a class like `Time`
for the `type` option in `expose` documentation resulted in an error
instead of generating the correct Swagger/OpenAPI specification.

This functionality was working correctly in v0.5.5 but regressed
after PR ruby-grape#75, leading to the following error:

```
GrapeSwagger::Errors::UnregisteredParser:
  No parser registered for Time.
```

The `primitive_type?` method now uses
`GrapeSwagger::DocMethods::DataType.call` to resolve the type
name before checking if it's a primitive type.
This ensures that types like `Time` are correctly identified as
strings with the `date-time` format, restoring the previous behavior.
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.

2 participants