All Projects → taymyr → lagom-openapi

taymyr / lagom-openapi

Licence: Apache-2.0 license
OpenAPI/Swagger module for Lagom

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language
scala
5932 projects

Projects that are alternatives of or similar to lagom-openapi

sbt-lagom-descriptor-generator
Lagom API code generator
Stars: ✭ 23 (-32.35%)
Mutual labels:  openapi, lagom
rdme
ReadMe's official CLI and GitHub Action
Stars: ✭ 44 (+29.41%)
Mutual labels:  openapi
apispec-webframeworks
Web framework plugins for apispec (formally in apispec.ext).
Stars: ✭ 25 (-26.47%)
Mutual labels:  openapi
rapiclient
Dynamic Open API (Swagger) Client for R
Stars: ✭ 55 (+61.76%)
Mutual labels:  openapi
yamlinc
Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
Stars: ✭ 103 (+202.94%)
Mutual labels:  openapi
quart-openapi
Module for Quart to add Flask-RESTPlus like functionality
Stars: ✭ 70 (+105.88%)
Mutual labels:  openapi
dataclasses-jsonschema
JSON schema generation from dataclasses
Stars: ✭ 145 (+326.47%)
Mutual labels:  openapi
stem
Event sourcing framework based on ZIO and pluggable runtime (currently working with Akka cluster)
Stars: ✭ 22 (-35.29%)
Mutual labels:  lagom
nx-trumbitta
💡An attempt to start collecting all of my Nx-related Open Source work in a mono-repo.
Stars: ✭ 31 (-8.82%)
Mutual labels:  openapi
datadog-api-client-python
Python client for the Datadog API
Stars: ✭ 44 (+29.41%)
Mutual labels:  openapi
cli
Panacloud Command Line Interface (CLI) uses the design-first approach for developing APIs. It generates Modern Multi-Tenant Serverless Cloud API infrastructure, mocks, stubs, tests, and stages using CDK. GraphQL schemas and OpenAPI specifications are used to implement the design-first approach.
Stars: ✭ 23 (-32.35%)
Mutual labels:  openapi
mapi-action
🤖 Run a Mayhem for API scan in GitHub Actions
Stars: ✭ 16 (-52.94%)
Mutual labels:  openapi
java-crud-api
No description or website provided.
Stars: ✭ 24 (-29.41%)
Mutual labels:  openapi
OpenAlchemy
Define SQLAlchemy models using the OpenAPI specification.
Stars: ✭ 39 (+14.71%)
Mutual labels:  openapi
lagom-java-maven-chirper-example
No description or website provided.
Stars: ✭ 17 (-50%)
Mutual labels:  lagom
HibiAPI
一个实现了多种常用站点的易用化API的程序 / A program that implements easy-to-use APIs for a variety of commonly used sites.
Stars: ✭ 427 (+1155.88%)
Mutual labels:  openapi
microblog-api
A modern (as of 2022) Flask API back end.
Stars: ✭ 218 (+541.18%)
Mutual labels:  openapi
optimade-python-tools
Tools for implementing and consuming OPTIMADE APIs in Python
Stars: ✭ 38 (+11.76%)
Mutual labels:  openapi
Unchase.OpenAPI.Connectedservice
📜 Visual Studio extension to generate OpenAPI (Swagger) web service reference.
Stars: ✭ 69 (+102.94%)
Mutual labels:  openapi
openapi-specification
Pinnacle REST API Open API Specification (swagger)
Stars: ✭ 20 (-41.18%)
Mutual labels:  openapi

Gitter Gitter_RU Build Status codecov Maven

OpenAPI/Swagger module for Lagom

The Lagom OpenAPI module has two common features:

  • Generation OpenAPI 3.X specification for the Lagom service by annotations. (How to use with Scala DSL/Java DSL)
  • Publishing static OpenAPI 3.X/Swagger 2.X specification from the classpath. (How to use with Scala DSL/Java DSL)

Also, you can see how to generate OpenAPI Specification for Lagom service on demo projects (Java/Maven example, Scala/Sbt example).

Versions compatibility

Lagom OpenAPI OpenAPI / Swagger Lagom 1.4 Lagom 1.5 Lagom 1.6 Scala 2.11 Scala 2.12 Scala 2.13
1.+ 2.0.7+

How to use

1.1 Generate (Scala DSL)

1.1.1 Dependencies

[Only for Lagom 1.4.X] You need to add next dependencies to the API module of Lagom service:

val swaggerAnnotations = "io.swagger.core.v3" % "swagger-annotations" % "2.0.7"
val lagomOpenapiApi = "org.taymyr.lagom" %% "lagom-openapi-scala-api" % lagomOpenapiVersion

lazy val `lagom-service-api` = (project in file("api"))
  .settings(
    libraryDependencies ++= Seq(
      ...
      swaggerAnnotations,
      lagomOpenapiApi
    )
  )

and next dependencies to the Implementation module of Lagom service:

val lagomOpenapiImpl = "org.taymyr.lagom" %% "lagom-openapi-scala-impl" % lagomOpenapiVersion

lazy val `lagom-service-impl` = (project in file("impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiImpl
    )
  )

1.1.2 Service Descriptor

Necessarily add OpenAPIDefinition annotation to Lagom service descriptor and extend (only for Lagom 1.4.X) descriptor by OpenAPIService trait:

@OpenAPIDefinition(
  info = new Info(
    version = "1.0.0",
    title = "My Service"
  ),
  ...
)
trait MyService extends OpenAPIService with Service {
  ...
}

Then you can use OpenAPI annotations for the methods of your service. For more information about annotations see the official wiki.

@Operation(...)
@Tag(...)
...
def method: ServiceCall[_, _]

[Only for Lagom 1.4.X] In conclusion, you must add the route for OpenAPI specification. You can do that with helper function withOpenAPI (default route is /_<service_name>/openapi)

override def descriptor: Descriptor = named("service")
    .withOpenAPI()
    ...

or use a custom route

override def descriptor: Descriptor = named("service")
    .withCalls(
      ...
      pathCall("/custom/route", openapi)
    )

1.1.3 Service implementation [Lagom 1.4.X]

Extend your service by the OpenAPIServiceImpl trait:

class MyServiceImpl(override val config: Config)
    extends MyService
    with OpenAPIServiceImpl {
      ...
}

1.1.4 Additional router [Lagom 1.5.X+]

Add additional router for your service

override lazy val lagomServer = {
  val service = wire[PetsServiceImpl]
  serverFor[PetsService](service)
    .additionalRouter(wire[OpenAPIRouter].router(service))
}

1.1.5 Conclusion

Now you can run service and get OpenAPI specification by a sent HTTP request to the registered route. For example by default:

curl "http://localhost:9000/_<service_name>/openapi[?format=json|yaml]"

1.2 Generate (Java DSL)

1.2.1 Dependencies

[Only for Lagom 1.4.X] You need to add next dependencies to the API module of Lagom service:

Maven

<dependencies>
    <dependency>
        <groupId>org.taymyr.lagom</groupId>
        <artifactId>lagom-openapi-java-api_${scala.binary.version}</artifactId>
        <version>${lagom.openapi.version}</version>
    </dependency>
    <dependency>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-annotations</artifactId>
        <version>2.0.7</version>
    </dependency>
</dependencies>

Sbt

val swaggerAnnotations = "io.swagger.core.v3" % "swagger-annotations" % "2.0.7"
val lagomOpenapiApi = "org.taymyr.lagom" %% "lagom-openapi-java-api" % lagomOpenapiVersion

lazy val `lagom-service-api` = (project in file("api"))
  .settings(
    libraryDependencies ++= Seq(
      ...
      swaggerAnnotations,
      lagomOpenapiApi
    )
  )

and next dependencies to the Implementation module of Lagom service:

Maven

<dependencies>
    <dependency>
        <groupId>org.taymyr.lagom</groupId>
        <artifactId>lagom-openapi-java-impl_${scala.binary.version}</artifactId>
        <version>${lagom.openapi.version}</version>
    </dependency>
</dependencies>

Sbt

val lagomOpenapiImpl = "org.taymyr.lagom" %% "lagom-openapi-java-impl" % lagomOpenapiVersion

lazy val `lagom-service-impl` = (project in file("impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiImpl
    )
  )

1.2.2 Service Descriptor

Necessarily add OpenAPIDefinition annotation to Lagom service descriptor and extend (only for Lagom 1.4.X) descriptor by OpenAPIService interface:

@OpenAPIDefinition(
  info = @Info(
    version = "1.0.0",
    title = "My Service"
  ),
  ...
)
public interface MyService extends OpenAPIService {
  ...
}

Then you can use OpenAPI annotations for the methods of your service. For more information about annotations see the official wiki.

@Operation(...)
@Tag(...)
...
ServiceCall<_, _> method();

[Only for Lagom 1.4.X] In conclusion, you must add the route for OpenAPI specification. You can do that with helper function withOpenAPI (default route is /_<service_name>/openapi)

@Override
default Descriptor descriptor() {
  return withOpenAPI(
    named("service")
      ...
  );
}

or use a custom route

@Override
default Descriptor descriptor() {
  return named("service")
    .withCalls(
      ...
      pathCall("/custom/route", this::openapi)
    );
}

1.2.3 Service implementation [Lagom 1.4.X]

[Only for Lagom 1.4.X] Extend your service by the abstract AbstractOpenAPIService:

public class MyServiceImpl extends AbstractOpenAPIService implements MyService {
      ...
}

1.2.4 Additional router [Lagom 1.5.X+]

Add additional router for your service

@Override
protected void configure() {
    OpenAPIRouter openAPIRouter = new OpenAPIRouter(
        getProvider(RoutingDsl.class),
        getProvider(MyServiceImpl.class),
        getProvider(Config.class)
    );
    bindService(MyService.class, MyServiceImpl.class, additionalRouter(openAPIRouter));
}

1.2.5 Conclusion

Now you can run service and get OpenAPI specification by a sent HTTP request to the registered route. For example by default:

curl "http://localhost:9000/_<service_name>/openapi[?format=json|yaml]"

2.1 Static (Scala DSL)

2.1.1 Dependencies

[Only for Lagom 1.4.X] You need to add next dependencies to the API module of Lagom service:

val lagomOpenapiApi = "org.taymyr.lagom" %% "lagom-openapi-scala-api" % lagomOpenapiVersion

lazy val `lagom-service-api` = (project in file("api"))
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiApi
    )
  )

and next dependencies to the Implementation module of Lagom service:

val lagomOpenapiImpl = "org.taymyr.lagom" %% "lagom-openapi-scala-impl" % lagomOpenapiVersion

lazy val `lagom-service-impl` = (project in file("impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiImpl
    )
  )

2.1.2 Service Descriptor

[Only for Lagom 1.4.X] Extend Lagom service descriptor by OpenAPIService trait:

trait MyService extends OpenAPIService with Service {
  ...
}

Add OpenAPI/Swagger specification file to classpath (typically src/main/resources folder) of API module. By default, the file should be named <service_name>.[yml|yaml|json].

openapi: 3.0.0
info:
  title: My Service
  version: 1.0.0
paths:
  ...

Also, you can change filename using openapi.file configuration in application.conf.

openapi.file = foobar.yml

[Only for Lagom 1.4.X] In conclusion, you must add the route for OpenAPI specification. You can do that with helper function withOpenAPI (default route is /_<service_name>/openapi)

override def descriptor: Descriptor = withOpenAPI(
  named("service")
    ...
)

or use a custom route

override def descriptor: Descriptor = named("service")
    .withCalls(
      ...
      pathCall("/custom/route?format", openapi)
    )

2.1.3 Service implementation [Lagom 1.4.X]

[Only for Lagom 1.4.X] Extend your service by the OpenAPIServiceImpl trait:

class MyServiceImpl(override val config: Config)
    extends MyService
    with OpenAPIServiceImpl {
      ...
}

2.1.4 Additional router [Lagom 1.5.X+]

Add additional router for your service

override lazy val lagomServer = {
  val service = wire[PetsServiceImpl]
  serverFor[PetsService](service)
    .additionalRouter(wire[OpenAPIRouter].router(service))
}

2.1.5 Conclusion

Now you can run service and get OpenAPI specification by a sent HTTP request to the registered route. For example by default:

curl "http://localhost:9000/_<service_name>/openapi[?format=json|yaml]"

2.2 Static (Java DSL)

2.2.1 Dependencies

[Only for Lagom 1.4.X] You need to add next dependencies to the API module of Lagom service:

Maven

<dependencies>
    <dependency>
        <groupId>org.taymyr.lagom</groupId>
        <artifactId>lagom-openapi-java-api_${scala.binary.version}</artifactId>
        <version>${lagom.openapi.version}</version>
    </dependency>
</dependencies>

Sbt

val lagomOpenapiApi = "org.taymyr.lagom" %% "lagom-openapi-java-api" % lagomOpenapiVersion

lazy val `lagom-service-api` = (project in file("api"))
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiApi
    )
  )

and next dependencies to the Implementation module of Lagom service:

Maven

<dependencies>
    <dependency>
        <groupId>org.taymyr.lagom</groupId>
        <artifactId>lagom-openapi-java-impl_${scala.binary.version}</artifactId>
        <version>${lagom.openapi.version}</version>
    </dependency>
</dependencies>

Sbt

val lagomOpenapiImpl = "org.taymyr.lagom" %% "lagom-openapi-java-impl" % lagomOpenapiVersion

lazy val `lagom-service-impl` = (project in file("impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      ...
      lagomOpenapiImpl
    )
  )

2.2.2 Service Descriptor

[Only for Lagom 1.4.X] Extend Lagom service descriptor by OpenAPIService interface:

public interface MyService extends OpenAPIService {
  ...
}

Add OpenAPI/Swagger specification file to classpath (typically src/main/resources folder) of API module. By default, the file should be named <service_name>.[yml|yaml|json].

openapi: 3.0.0
info:
  title: My Service
  version: 1.0.0
paths:
  ...

Also, you can change filename using openapi.file configuration in application.conf.

openapi.file = foobar.yml

[Only for Lagom 1.4.X] In conclusion, you must add the route for OpenAPI specification. You can do that with helper function org.taymyr.lagom.javadsl.openapi.OpenAPIUtils#withOpenAPI (default route is /_<service_name>/openapi)

@Override
default Descriptor descriptor() {
  return withOpenAPI(
    named("service")
      ...
  );
}

or use a custom route

@Override
default Descriptor descriptor() {
  return named("service")
    .withCalls(
      ...
      pathCall("/custom/route?format", this::openapi)
    );
}

2.2.3 Service implementation [Lagom 1.4.X]

Extend your service by the abstract AbstractOpenAPIService:

public class MyServiceImpl extends AbstractOpenAPIService implements MyService {
      ...
}

2.2.4 Additional router [Lagom 1.5.X+]

Add additional router for your service

@Override
protected void configure() {
    OpenAPIRouter openAPIRouter = new OpenAPIRouter(
        getProvider(RoutingDsl.class),
        getProvider(MyServiceImpl.class),
        getProvider(Config.class)
    );
    bindService(MyService.class, MyServiceImpl.class, additionalRouter(openAPIRouter));
}

2.2.5 Conclusion

Now you can run service and get OpenAPI specification by a sent HTTP request to the registered route. For example by default:

curl "http://localhost:9000/_<service_name>/openapi[?format=json|yaml]"

Contributions

Contributions are very welcome.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].