Skip to content

OpenAPI: support optional attributes and Array<> syntax in inline sch…#228

Open
ayushman1210 wants to merge 2 commits intorage-rb:mainfrom
ayushman1210:fix/227
Open

OpenAPI: support optional attributes and Array<> syntax in inline sch…#228
ayushman1210 wants to merge 2 commits intorage-rb:mainfrom
ayushman1210:fix/227

Conversation

@ayushman1210
Copy link

@ayushman1210 ayushman1210 commented Mar 6, 2026

Description
This PR addresses two limitations in the inline YAML schema parser used for @request and @response tags, as described in the issue

  1. Optional Attributes (? suffix): Inline schemas now support marked optional attributes using the ? suffix (e.g., name?: String).
  • Attributes without the suffix are now automatically added to the required array in the generated OpenAPI specification.
  • Attributes with the suffix are treated as non-required and are excluded from the required list

2.Array<> Syntax Support: Added support for the Array syntax inside inline schemas to provide a consistent alternative to the unary array [Type] syntax.

  • Example: { errors: Array } now correctly generates an array of strings

Changes
File --> lib/rage/openapi/parsers/yaml.rb

  • Updated __parse to handle key stripping and required array generation.
  • Updated type_to_spec to recognize and parse the Array<...> string format.

File --> spec/openapi/parsers/yaml_spec.rb

  • Added new test cases for optional/required attribute mixing and nested Array<> usage.
  • Updated existing expectations to include the required property where applicable.

Verification

  1. Added new RSpec tests covering mixed attribute optionality and varied Array<> types (String, Integer, Hash).
  2. Verified that all existing tests pass with the adjusted requirements.
  3. Manual verification of the parser logic with a standalone test script.

Fixes #227

@ayushman1210
Copy link
Author

Hi @rsamoilov please review this pr when you have some free time and let me know if anything else needed
thanks !!

Copy link
Member

@rsamoilov rsamoilov left a comment

Choose a reason for hiding this comment

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

Hy @ayushman1210

Left one small comment. Otherwise, looks good 👍

@ayushman1210 ayushman1210 requested a review from rsamoilov March 7, 2026 08:28
Copy link
Member

@rsamoilov rsamoilov left a comment

Choose a reason for hiding this comment

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

Hi @ayushman1210

This looks good. The only thing is that this doesn't seem to support enums. For example, the [IN_PROGRESS, COMPLETED] expression creates an enum, but Array<IN_PROGRESS, COMPLETED> is not parsed correctly.

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.

[OpenAPI] Inline schema improvements: optional attributes and Array<> syntax

2 participants