swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.39k stars 2.18k forks source link

Have class-level @Extensions append extensions to operations #3249

Open judu opened 5 years ago

judu commented 5 years ago

Hi,

We are working on our (jersey) client generation. We wish to use extensions to document "services". A service is a set of paths around the same type of resources. When we generate our client, we want to generate an "addon" service, an "organisation" service, an "invoice" service, etc.

We can add an x-service extension to each and every method, but that would be a lot of replicated code. So I'm trying to be smart ;)

I saw that @Extensions can be applied to classes. I added that to my class:

@Extension(properties = {
   @ExtensionProperty(name = "service", value = "addon")
})
public class AddonsAPI {
…

When I generate the swagger, there is no mention of x-service anywhere.

We think that using @Extension on classes (which is allowed by the definition of that annotation) should add the extension to all operations in that class.

What do you think? If this is not the use case, then what is the use of @Extension on classes?

MattBlissett commented 1 year ago

I'd also like this for code reuse, but for methods.

Instead of:

  @Operation(
    operationId = "getOccurrenceById",
    summary = "Occurrence by id",
    description = "...",
    extensions = @Extension(
        name = "Category",
        properties = @ExtensionProperty(name = "Level", value = "Basic")
    )
  )
  public ...

where the same extension is repeated on many methods, I'd be able to define an annotation:

  @Target({METHOD})
  @Retention(RetentionPolicy.RUNTIME)
  @Inherited
  @Extension(
        name = "Category",
        properties = @ExtensionProperty(name = "Level", value = "Basic")
  )
  @interface CategoryLevelBasic {}

and use that:

  @Operation(
    operationId = "getOccurrenceById",
    summary = "Occurrence by id",
    description = "..."
  )
  @CategoryLevelBasic
  public ...