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

AffordanceBuilder GET methods not listed #31

Closed
Wykiki opened this issue Jan 31, 2018 · 3 comments
Closed

AffordanceBuilder GET methods not listed #31

Wykiki opened this issue Jan 31, 2018 · 3 comments
Assignees

Comments

@Wykiki
Copy link

Wykiki commented Jan 31, 2018

Hello,

I've tried to reference some hydra:operation in my responses, but whatever the Annotations I put on the controller, I can't show them in the operations list.

The Controller Interface :

@Api(value = "hydra", description = "the hydra API")
public interface HydraApi {

    @ApiOperation(value = "", notes = "", response = Void.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Successfully added device", response = Void.class) })
    
    @RequestMapping(value = "/hydra/device",
        produces = { "application/ld+json" }, 
        method = RequestMethod.POST)
    ResponseEntity<Object> add(@ApiParam(value = "" ,required=true )  @Valid @RequestBody Device body);


    @ApiOperation(value = "", notes = "", response = Void.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Successfully deleted device", response = Void.class) })
    
    @RequestMapping(value = "/hydra/device",
        produces = { "application/ld+json" }, 
        method = RequestMethod.DELETE)
    ResponseEntity<Object> delete(@ApiParam(value = "" ,required=true )  @Valid @RequestBody Device body);


    @ApiOperation(value = "", notes = "", response = DeviceData.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Successfully read device data", response = DeviceData.class) })
    
    @RequestMapping(value = "/hydra/device/read/{maker}/{model}/{serial}",
        produces = { "application/ld+json" }, 
        method = RequestMethod.GET)
    ResponseEntity<Object> read(@ApiParam(value = "Maker of the device",required=true ) @PathVariable("maker") String maker,
                                @ApiParam(value = "Model of the device",required=true ) @PathVariable("model") String model,
                                @ApiParam(value = "Serial of the device",required=true ) @PathVariable("serial") String serial);


    @ApiOperation(value = "", notes = "", response = EntryPoint.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "The API endpoints", response = EntryPoint.class) })
    
    @RequestMapping(value = "/hydra",
        produces = { "application/ld+json" }, 
        method = RequestMethod.GET)
    ResponseEntity<Object> rootEntryPoint();

}

The Resource builder :

    public ResponseEntity<Object> process() {
        ResponseEntity ret;

        try {
            Resource<EntryPoint> entryPointResource =
                    new Resource<>(new EntryPoint());

            entryPointResource.add(
                    linkTo(methodOn(HydraApi.class).add(new Device()))
                            .and(linkTo(methodOn(HydraApi.class).delete(new Device())))
                            .and(linkTo(methodOn(HydraApi.class).read("a", "b", "c")))
                            .withSelfRel()
            );
            ret = new ResponseEntity<Resource>(
                    entryPointResource,
                    HttpStatus.OK
            );
        } catch (Exception e) {
            ret = resolveException(e);
        }
        return new ResponseEntity<>(ret.getBody(), ret.getStatusCode());
    }

The response of the Resource builder :

{
  "@context": {
    "@vocab": "http://schema.org/"
  },
  "@type": "EntryPoint",
  "@id": "http://localhost:8080/hydra/device",
  "hydra:operation": [
    {
      "hydra:method": "POST",
      "hydra:expects": {
        "@type": "Device",
        "hydra:supportedProperty": [
          {
            "hydra:property": "serial"
          },
          {
            "hydra:property": "maker"
          },
          {
            "hydra:property": "model"
          }
        ]
      }
    },
    {
      "hydra:method": "DELETE",
      "hydra:expects": {
        "@type": "Device",
        "hydra:supportedProperty": [
          {
            "hydra:property": "serial"
          },
          {
            "hydra:property": "maker"
          },
          {
            "hydra:property": "model"
          }
        ]
      }
    }
  ]
}

Thanks in advance for the answer !

@dschulten
Copy link
Owner

The GET method is not listed because I felt it is implied in Hydra that you can GET a Resource. Seeing that you also have swagger annotations, I guess you are interested in showing the returned type. Is there anything else you want to see on the GET description?

@dschulten dschulten self-assigned this Mar 20, 2018
@Wykiki
Copy link
Author

Wykiki commented Mar 21, 2018

I'm absolutely not a Hydra Guru, so you're probably right about Hydra implicitly allowing the GET of the Resource.

So does it mean that a GET endpoint can't "expect" anything ?

Yes, it is managed with Swagger. And yes, it would be nice to show the returned type !

@dschulten
Copy link
Owner

fixed as of 0.4.1, we now describe the GET operation

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