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

Deference hyperlink parameter before deriving the resource name #341

Merged
merged 1 commit into from
Mar 6, 2019

Conversation

syskill
Copy link
Contributor

@syskill syskill commented Feb 26, 2019

No description provided.

@geemus
Copy link
Member

geemus commented Mar 1, 2019

It's been a bit since I've worked with this (which makes it hard for me to recall some particulars). Could you provide a quick before/after example of what this would look like in practice? That way I can be more confident about the impact. Thanks!

@syskill
Copy link
Contributor Author

syskill commented Mar 5, 2019

pr-example.yaml.txt

Here is an example of a recurring pattern in my REST API. There are two resources, example frobs and example blobs. Frobs have one or more ancillary blobs. I have a CLI tool, generated automatically from the schema, with syntax like

$ exampletool example_frobs add_ancillary_blob example_frob=thisfrob ancillary_blob=3
$ exampletool example_frobs remove_ancillary_blob example_frob=thatfrob ancillary_blob=7

In order to generate sensible CLI syntax, I need the link parameter for ancillary blobs to end in /ancillary_blob; hence the definition #/definitions/example_frob/definitions/ancillary_blob.

Now, when I run prmd to generate an API doc, it cleverly dereferences #/definitions/example_frob/definitions/ancillary_blob to #/definitions/example_blob/definitions/id (there's an anyOf but it doesn't matter). Great! Except that prmd has already derived the resource name before dereferencing, so it names the link parameter example_frob_id. The example command is therefore rather misleading:

$ curl -n -X PUT http://example.org/example-frobs/$EXAMPLE_FROB_NAME_OR_ID/ancillary-blobs/$EXAMPLE_FROB_ID \
  -H "Content-Type: application/json"

After this commit, prmd gets it right:

$ curl -n -X PUT http://example.org/example-frobs/$EXAMPLE_FROB_NAME_OR_ID/ancillary-blobs/$EXAMPLE_BLOB_ID \
  -H "Content-Type: application/json"

@geemus
Copy link
Member

geemus commented Mar 6, 2019

I see, I don't think in my usage I've had nested definitions like that, which might be why I hadn't come across it. That all makes sense, thanks for taking the time to explain and share examples. LGTM.

@geemus geemus merged commit d4908cb into interagent:master Mar 6, 2019
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