Skip to content

fix for the empty ref attribute of RequestBody annotation#2

Closed
diuis wants to merge 1 commit into
apache:masterfrom
diuis:fix-requestbodyimpl-ref
Closed

fix for the empty ref attribute of RequestBody annotation#2
diuis wants to merge 1 commit into
apache:masterfrom
diuis:fix-requestbodyimpl-ref

Conversation

@diuis
Copy link
Copy Markdown

@diuis diuis commented Aug 1, 2018

When a jax-rs method parameter is annotated in this way, without the ref attribute:

  public AssetViewModel create(@RequestBody(
                                            name = "asset",
                                            description = "request body in json format",
                                            content = @Content(
                                                               mediaType = APPLICATION_JSON,
                                                               schema = @Schema(name = "Asset", 
                                                                                                  implementation = AssetViewModel.class)),
                                                               required = true) final AssetViewModel _asset) {

    _log.log(Level.INFO, "Creating {0}", _asset);

    return _asset;
  }

this code:
this._ref = _ref.startsWith("#") ? _ref : ("#/components/requestBodies/" + _ref); generates an invalid openapi json:

"/api/asset":{
      "post":{
        "deprecated":false,
        "description":"api to create a new Asset",
        "operationId":"create",
        "parameters":[
        ],
        "requestBody":{
          "$ref":"#/components/requestBodies/",

I think that isn't correct, and swagger-ui complains with the error:

Resolver error at paths./api/asset.post.requestBody.$ref
Could not resolve reference because of: Could not resolve pointer: /components/requestBodies/ does not exist in document

@diuis
Copy link
Copy Markdown
Author

diuis commented Aug 1, 2018

@rmannibucau please take a look at this pr

@rmannibucau
Copy link
Copy Markdown
Contributor

Hi @diuis
Do you mind adding a test? Updated a oot of these issues earlier today and wonder if it was missed.
Also the fix shouldnt be in setref peobably but in the caller, wdyt?

@diuis
Copy link
Copy Markdown
Author

diuis commented Aug 2, 2018

Hi @rmannibucau , your abd695b commit fixed the RequestBody empty ref bug:

if (!requestBody.ref().isEmpty()) {
                impl.ref(requestBody.ref());
}

I will close my PR.
Thanx!

@diuis diuis closed this Aug 2, 2018
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