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

Required fields from rules() are not parsed into OpenAPI file #916

Closed
1 task done
torgeros opened this issue Nov 8, 2024 · 6 comments
Closed
1 task done

Required fields from rules() are not parsed into OpenAPI file #916

torgeros opened this issue Nov 8, 2024 · 6 comments
Labels
bug Something isn't working triage

Comments

@torgeros
Copy link

torgeros commented Nov 8, 2024

Scribe version

4.38.0

PHP version

8.3.10 (cli)

Framework

Laravel

Framework version

10.48.20

Scribe config

base_url => "http://localhost:8000"
static.output_path => "scribe_docs"

What happened?

I have rules() that should tag object members as required.

For the generated scribe html file, everything not-required is correctly tagged as optional.
However, the generated openapi.yaml does not set required for all fields that are not optional.

Interestingly, member of objects in objects do not seem to work, while members of objects in arrays do.

Nested Object case (does not work)

This is a section of my rules function:

public function rules(): array
{
    return [
        'whitelabel' => 'string',
        'isPreview' => 'boolean',

        'issuer.email' => 'required|email',
        'issuer.phone' => 'nullable|string'

        // more rules...
    ];
}

This is the generated (& rendered) OpenAPI document:

image

And this is what I would expect (I changed the openapi doc manually):

image

Array of Objects case (does work!)

rules() snippet:

        'items.*.description' => 'string',
        'items.*.quantity' => 'required|numeric',

Generated OpenAPI doc:

image

Docs

@torgeros torgeros added bug Something isn't working triage labels Nov 8, 2024
@shalvah
Copy link
Contributor

shalvah commented Nov 9, 2024

I think that's fixed by #905. I'll try to tag a release soon.

@shalvah shalvah closed this as completed Nov 9, 2024
@AryaSvitkona
Copy link

AryaSvitkona commented Jan 13, 2025

I'm not sure it I should create a new issue or just add the feedback here.

We are facing the same issue with the required rule in our form request, but the update to the latest version 4.39.0 did not solve the issue.

Scribe version
4.39.0

PHP version
8.3.8 (cli)

Framework
Laravel

Framework version
11.34.2

Scribe config

'type' => 'external_static',

    // See https://scribe.knuckles.wtf/laravel/reference/config#theme for supported options
    'theme' => 'elements',

Rules

public function rules(): array {
        return [
            'meta.creation-date' => ['required', new Iso8601()],
            'data.*.creation-date' => ['required', new Iso8601()],
        ];
    }

Screenshot:
Screenshot 2025-01-13 at 10 59 59

OpenAPI

      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                meta:
                  type: object
                  description: ''
                  
                  nullable: false
                  properties:
                    creation-date:
                      type: string
                      description: ''
                      example: et
                      nullable: false
                   required: // Line is missing
                      - creation-date // Line is missing
                data:
                  type: array
                  description: ''
                  example:
                    - []
                  items:
                    type: object
                    properties:
                      creation-date:
                        type: string
                        description: ''
                        example: magni
                        nullable: false
                    required:
                      - creation-date
      security: []

Expected behaviour:
Both properties are marked as required

I tried to understand the logic how a required parameter is extracted, set and written into the OpenAPI spec, but seems to be a little to complex.

@torgeros
Copy link
Author

@AryaSvitkona There is an indentation error in your yaml

                  properties:
                    creation-date:
                      type: string
                      description: ''
                      example: et
                      nullable: false
    HERE           required: //missing
                      - creation-date

@AryaSvitkona
Copy link

@torgeros That may be true, but that line was added to point to the issue ;)
That's why the //missing was added.

@AryaSvitkona
Copy link

@shalvah can we reopen this issue or should I add a new one?

@shalvah
Copy link
Contributor

shalvah commented Jan 19, 2025

Please open a new issue, thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

3 participants