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

Validator ignores base uri path #3

Closed
scaytrase opened this issue May 7, 2019 · 7 comments
Closed

Validator ignores base uri path #3

scaytrase opened this issue May 7, 2019 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@scaytrase
Copy link
Contributor

scaytrase commented May 7, 2019

Given openapi spec with
Server base uri http://localhost:8000/api/v1
POST operation /products.create

I expect POST request http://localhost:8000/api/v1/products.create to be valid

Actual result

OpenAPI spec contains no such operation [/api/v1/products.create,post]
        $yaml = /** @lang yaml */
            <<<YAML
openapi: 3.0.0
info:
  title: Product import API
  version: '1.0'
servers:
  - url: 'http://localhost:8000/api/v1'
paths:
  /products.create:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              properties:
                test:
                  type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                properties:
                  result: 
                    type: string
YAML;

        $validator = new ServerRequestValidator(CebeReader::readFromYaml($yaml));

        $psrRequest = new ServerRequest(
            'POST',
            'http://localhost:8000/api/v1/products.create'
        );

        $validator->validate($psrRequest);

According to https://swagger.io/docs/specification/api-host-and-base-path/ having base url path prefix is totally valid

@lezhnev74
Copy link
Owner

Good catch! Ill fix it asap. Now focusing on security keyword.

@lezhnev74 lezhnev74 added the bug Something isn't working label May 7, 2019
@lezhnev74 lezhnev74 self-assigned this May 7, 2019
@lezhnev74
Copy link
Owner

@scaytrase I've completed first iteration over base uri feature.
Your test looks green now: https://github.com/lezhnev74/openapi-psr7-validator/blob/master/tests/FromCommunity/ScayTraseTest.php

I noticed that you did not add type:object before properties. I thought that was a violation of OAS 3.

@cebe
Copy link

cebe commented May 7, 2019

I noticed that you did not add type:object before properties. I thought that was a violation of OAS 3.

the spec does not mention this explicitly anywhere, but tools tend to assume type object when properties is specified.

@scaytrase
Copy link
Contributor Author

scaytrase commented May 7, 2019

assume or require? i validate my schema against https://editor.swagger.io, so they should be pretty valid, but it's interesting question anyway

@lezhnev74
Copy link
Owner

I've removed this check. I was applying "defensive programming" and wanted to protect the code from unexpected side effects.

@lezhnev74
Copy link
Owner

I'll allocate some time for testing different servers values, gonna close this one once confirmed that it works as expected.

@scaytrase
Copy link
Contributor Author

Yeah, I've just updated to 0.7 and this looks like fixed at the moment

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

No branches or pull requests

3 participants