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 (or document how to) read schema properties #163

Open
tacman opened this issue Jun 13, 2022 · 4 comments
Open

Add (or document how to) read schema properties #163

tacman opened this issue Jun 13, 2022 · 4 comments
Labels
needs more info More information is needed to reproduce the issue.

Comments

@tacman
Copy link

tacman commented Jun 13, 2022

I'm using this library to read the description and example properties from the schema, but it seem that those properties are protected.

Perhaps I'm missing something, maybe it's there. If not, what do you think about a PR that basically adds getProperties to the schema that returns the now-protected properties?

@dearsina
Copy link

dearsina commented Jun 14, 2022

Weirdly enough, I'm here for the exact same reason. How do I read for instance all of the expected responses for a given path?

I got this far:

foreach($openapi->paths as $path => $definition) {
	foreach($definition->get->responses as $code => $response){
		var_dump($code);
		var_dump($response->get);
	}
}

But this will result in the below, and I'm a little stuck how to get for instance the schema other than using the getSerializableData() method, because that won't work when the value is a reference:

int(200)
object(cebe\openapi\spec\Response)#51 (10) {
  ["_properties":"cebe\openapi\SpecBaseObject":private]=>
  array(2) {
    ["description"]=>
    string(7) "Success"
    ["schema"]=>
    array(2) {
      ["type"]=>
      string(6) "string"
      ["example"]=>
      array(2) {
        ["Status"]=>
        string(7) "Success"
        ["Result"]=>
        array(1) {
          ["credits"]=>
          string(4) "5000"
        }
      }
    }
  }
 (...)
}

@cebe
Copy link
Owner

cebe commented Jun 20, 2022

I'm using this library to read the description and example properties from the schema, but it seem that those properties are protected.

what makes you think that? what is the code you tried? if you have a Schema object, you can access the properties by $schema->example or $schema->description...

How do I read for instance all of the expected responses for a given path?

Exactly as you did. What is wrong with the result? you are getting the response code int(200) and the Response object for it.
$response->description should give you the description.

@cebe cebe added the needs more info More information is needed to reproduce the issue. label Jun 20, 2022
@tacman
Copy link
Author

tacman commented Jun 20, 2022

Again, maybe I'm not using the library right, could you add a snippet the the documentation?

        $openapi = Reader::readFromJsonFile($fn = $bag->get('kernel.project_dir') . '/openapi.json');
        foreach ($openapi->components->schemas as $schema) {
            dd($schema);
            // $properties = $schema->getProperties(); //<--   this does't work
        }

image

@dearsina
Copy link

@cebe I think the challenge is that at times, I won't know what property keys are available and it would be useful to have access to all of them instead of querying each one to see if they exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is needed to reproduce the issue.
Projects
None yet
Development

No branches or pull requests

3 participants