-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Description
Inline YAML schemas used in @request and @response tags currently have two limitations:
1. No support for optional attributes
When using an inline schema like @response { id: Integer, name: String, email: String }, all attributes are treated as non-required in the generated OpenAPI specification. There is no way to distinguish between required and optional attributes.
The @param tag already supports the ? suffix to mark optional parameters. The same convention should work for inline schema attributes. Attributes without the ? suffix should be marked as required, while attributes with the suffix should be non-required.
For example:
class Api::V1::UsersController < ApplicationController
# @request { name?: String, email: String, password: String }
def create
end
endShould generate:
schema:
type: object
required:
- email
- password
properties:
name:
type: string
email:
type: string
password:
type: stringNote that name is still included in properties (without the ?), but is excluded from the required list.
2. No Array<> syntax for inline schema values
The Array<> syntax is already supported for top-level references (e.g. @response Array<UserResource>), and the [] syntax works inside inline schemas (e.g. { errors: [String] }). However, Array<> is not supported inside inline schemas.
The following should work equivalently:
# Currently supported
# @response 422 { errors: [String] }
# Should also be supported
# @response 422 { errors: Array<String> }Both should generate:
schema:
type: object
properties:
errors:
type: array
items:
type: stringTips
- Check the OpenAPI docs to understand how inline schemas,
@request, and@responsetags work. - Look at how the inline schema parser currently handles the
[]syntax - extending it to also acceptArray<>should follow a similar pattern. - The OpenAPI specification on required properties describes how
requiredworks in object schemas. - Check the architecture doc that shows how Rage's core components interact with each other and outlines the design principles.
- Feel free to ask any questions or request help in the comments below!