cancel
Showing results for 
Search instead for 
Did you mean: 

Question about Swagger 2.X Annotations

SOLVED
Occasional Contributor

Question about Swagger 2.X Annotations

Hi 

 

I want to use Object(like sample below :Contractor) to get input values from the frontend.


May I use the @RequestBody annotation to define which parameters will pass(not all parameters in the Object)

from the frontend?

 

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response insert(@RequestBody(description = "Created contractor object", required = true,
            content = @Content(
                    schema = @Schema(implementation = Contractor.class)))Contractor contractor) {
...
}

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Staff

Re: Question about Swagger 2.X Annotations

This is achievable in latest 2.0.8-SNAPSHOT version and upcoming release by providing an unnamed example to the content, as in test https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/test/java/io/swag...

 

Before 2.0.8-SNAPSHOT unnamed examples were not supported, you could still add named examples as in https://github.com/swagger-api/swagger-core/blob/898bccdd72c2982f51e2cdab9baac53b7f2c7ac1/modules/sw..., but they not yet supported by UI (support will come soon)

 

View solution in original post

4 REPLIES 4
Community Hero

Re: Question about Swagger 2.X Annotations

Is swagger definition available? Then swagger code gen utility can be used to generate stubs.


Regards,
Rao.
Staff

Re: Question about Swagger 2.X Annotations

assuming this in scope of usage of swagger-core to resolve an OpenAPI spec from a JAXRS project, you can indeed use @RequestBody (in the specific case you can even skip that, as the parameter Type will be resolved as requestBody); If you need to hide specific properties (if this is what you mean with "not all parameters in the Object") in Contractor, you can add @Hidden annotations there to the properties you want to hide.

Highlighted
Occasional Contributor

Re: Question about Swagger 2.X Annotations

Thanks for your response.

I will show some pics to describe my question.

I want my swagger ui show like below

  • schema show all of my Course parameters

1.JPG

  • example value show part of my Course parameters

2.JPG

 

I use this code ,but not working.

 

@POST
	@Operation(summary = "insert new course")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response insert(@RequestBody(required = true,
			content = @Content(schema = @Schema(implementation = Course.class,
                    example = "{'courseName': 'test','courseType': 'testtest','courseDescription': 'myDescription'}"))) Course course,
			
			@Context HttpServletRequest request,
			@Context HttpServletResponse response) {
		return null;
	}

 

Is it possible make schema and example value different with annotations?

 

 

Thanks

 

Staff

Re: Question about Swagger 2.X Annotations

This is achievable in latest 2.0.8-SNAPSHOT version and upcoming release by providing an unnamed example to the content, as in test https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/test/java/io/swag...

 

Before 2.0.8-SNAPSHOT unnamed examples were not supported, you could still add named examples as in https://github.com/swagger-api/swagger-core/blob/898bccdd72c2982f51e2cdab9baac53b7f2c7ac1/modules/sw..., but they not yet supported by UI (support will come soon)

 

View solution in original post

New Here?
Join us and watch the welcome video:
Watch the new Interview