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

Add enum list to Open API spec response properties #902

Conversation

coreymcmahon
Copy link
Contributor

Thanks for all you do! Scribe has been immensely useful and has simplified our documentation workflow significantly.

This PR includes an update which allows enum types defined via ResponseField to flow through to the response properties in the Open API spec. For example:

class GetStoreController extends Controller
{
    #[ResponseField("status", enum: StoreStatus::class)]
    #[ResponseFromDataObject(StoreResource::class, Store::class)]
    public function __invoke()
    {
        // etc...
    }
}

... results in:

openapi: 3.0.3
info:
  title: 'Test API'
  description: ''
  version: 1.0.0
servers:
  -
    url: 'https://devserver.dev'
paths:
  /v1/resolve:
    get:
      summary: 'Get Store'
      operationId: getStore
      description: 'Fetches the essential store information'
      responses:
        200:
          description: ''
          content:
            application/json:
              schema:
                type: object
                example:
                  id: 1
                  status: open
                properties:
                  id:
                    type: integer
                    example: 1
                  status:
                    type: string
                    example: open
                    enum:
                      - open
                      - restricted
                      - closed
                      - permanently_closed

Previously (before this commit) the enum key was omitted.

There was already a PR to include the enum values in the query params, this simply implements the same behaviour for the response parameters.

Note that this does not work for response bodies where the entire payload is wrapped in a data key, I'll try and address this in a later PR.

@shalvah shalvah merged commit e35e6da into knuckleswtf:master Oct 18, 2024
6 checks passed
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