rest-schemagen icon indicating copy to clipboard operation
rest-schemagen copied to clipboard

Schema does not contain information about all parameters

Open C-Otto opened this issue 5 years ago • 9 comments

In LinkCreator.createFor (line 133) the schema is only generated for the last resource on the path, information from previous resources is ignored.

C-Otto avatar May 08 '19 13:05 C-Otto

Not sure if I understand your question correctly. If you have subresources, you have to give the full chain of resources so that the generator is able to create the path correctly. The method for which the link is created has to be on the last resource.

wuan avatar May 08 '19 14:05 wuan

The path is generated correctly, but the schema is not. The full chain is given, but only the last segment of it is used at the code I mentioned.

C-Otto avatar May 08 '19 14:05 C-Otto

Do you have an example of a case where this is wrong. Is it the case where a subresource method is not allowed and this is not considered here or do you miss query or path parameters from one of the subresource methods before?

wuan avatar May 09 '19 19:05 wuan

I have one back at Mercateo, I will show you on Monday if you're interested. We had the issue with a path /api/shops/{shop id}/something/{something id}. In the schema only the {something id} was documented, but not {shop id}.

There is a resource for /api/shops/, and another resource for /api/shops/{shop id}/something/.

What I miss is the schema information for {shop id}. The path is correct. I fail do understand how to make this clearer, the very first word of this issue is "schema" after all.

C-Otto avatar May 10 '19 07:05 C-Otto

So your path parameter shop_id should be also contained in the input and/or output schema objects of the endpoint as well? Then it is not only a path parameter, but some kind of redundancy in the payload as well. This can be achieved by using an allowed value object (aka ENUM) with the shop_id being set to the desired value.

wuan avatar May 10 '19 08:05 wuan

When i get it right he want's to have a template link with the parameter not set.

JoergAdler avatar May 10 '19 08:05 JoergAdler

Then lets better base this on an example or a failing test.

wuan avatar May 10 '19 13:05 wuan

imgpsh_mobile_save

This is the result created using the library. As you can see the schema contains the last path variable {id}, but not the one before {app-id}.

This issue is caused by the code line I mentioned above.

Does that help?

C-Otto avatar May 13 '19 08:05 C-Otto

The problem is that in the method addSchemaIfNeeded only the lastScopedMethod is used: https://github.com/Mercateo/rest-schemagen/blob/af1d28141c9f3b1ccf00c0a1da7196378bfe3598/src/main/java/com/mercateo/common/rest/schemagen/link/LinkCreator.java#L135

Busoniu avatar Jun 09 '20 10:06 Busoniu