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

Curl example does not respect non-JSON encType when using POST #296

Open
duckpunch opened this issue May 24, 2016 · 5 comments
Open

Curl example does not respect non-JSON encType when using POST #296

duckpunch opened this issue May 24, 2016 · 5 comments

Comments

@duckpunch
Copy link

I think the greater issue is that encType for links is just not supported, but this is the specific problem I ran into.

In the Hyper-Schema spec, there is a snippet that looks like this.

{
    "links": [{
        "encType": "application/x-www-form-urlencoded",
        "method": "GET",
        "href": "/Product/",
        "properties": {
            "name": {
                "description": "name of the product"
            }
        }
    }]
}

In my case, I'm essentially trying the same thing, but instead with method=POST. The curl example from the outputted Markdown shows a JSON body.

@geemus
Copy link
Member

geemus commented May 25, 2016

I think this was just a naive, good-enough solution since we only happen to use json bodies. I'd be open to discussing a PR that uses this info to make choices about how to format the examples. I suspect we should just maintain json as the default for backwards compatibility.

@duckpunch
Copy link
Author

How about switching the example when either properties or schema is provided for a link?

That is, if schema is provided, it works like it does today.

If properties is provided, the example shows

curl <url>
    -d foo=bar \
    -d bar=foo \
    -H "Content-Type: <encType>"

If both are provided, prefer using schema (maintaining the current implementation).

Alternatively, there could be an option to either override or omit the curl example.

@geemus
Copy link
Member

geemus commented May 26, 2016

Hmm. I worry that leaves a lot to implied behavior, could we just explicitly check/rely upon the contents of encType instead of presence/absence of other data?

@duckpunch
Copy link
Author

Switching on the encType seems reasonable.

I'm not quite sure what to do if you say something like encType=application/x-www-form-urlencoded and provide a schema. The spec almost seems to suggest that it's a JSON body.

for a POST request, this would define the body

@geemus
Copy link
Member

geemus commented May 31, 2016

Yeah, maybe we could just do things if encType and example are both present? But maybe it should try to do something with the schema. Yeah, the spec does point to GET query, POST body, but I think you can also put form encoded stuff in the body and be valid?

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

No branches or pull requests

2 participants