Introduction
In my last blog I showed a simple example app annotated with Eclipse MicroProfile OpenAPI Annotation. See https://magnus-k-karlsson.blogspot.com/2021/05/auto-generate-openapiswagger.html
Here will deploy it on Wildfly and call OpenAPI.
Wildfly 23.0.2.Final
On Wildfly is Eclipse MicroProfile already installed and all you need is to start it with the correct configuration.
$ ./standalone.sh -c standalone-microprofile.xml
And then call it
$ curl http://localhost:8080/openapi
---
openapi: 3.0.3
info:
title: example-openapi-swagger.war
version: "1.0"
servers:
- url: /example-openapi-swagger
paths:
/api/persons:
get:
summary: Get all persons.
description: Get all persons in DB.
parameters:
- name: name
in: query
description: The name to search for.
required: false
schema:
type: string
example: '*he*'
responses:
"500":
description: Internal Error
content:
application/json: {}
"200":
description: All persons in DB.
content:
application/json:
schema:
$ref: '#/components/schemas/Person'
components:
schemas:
Person:
type: object
properties:
age:
format: int32
type: integer
name:
type: string
And to get JSON instead.
$ curl http://localhost:8080/openapi?format=JSON
{
"openapi" : "3.0.3",
"info" : {
"title" : "example-openapi-swagger.war",
"version" : "1.0"
},
"servers" : [ {
"url" : "/example-openapi-swagger"
} ],
"paths" : {
"/api/persons" : {
"get" : {
"summary" : "Get all persons.",
"description" : "Get all persons in DB.",
"parameters" : [ {
"name" : "name",
"in" : "query",
"description" : "The name to search for.",
"required" : false,
"schema" : {
"type" : "string"
},
"example" : "*he*"
} ],
"responses" : {
"500" : {
"description" : "Internal Error",
"content" : {
"application/json" : { }
}
},
"200" : {
"description" : "All persons in DB.",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Person"
}
}
}
}
}
}
}
},
"components" : {
"schemas" : {
"Person" : {
"type" : "object",
"properties" : {
"age" : {
"format" : "int32",
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
}
}
}
JBoss EAP 7.3
The JBoss EAP does not come bundled with OpenAPI and you need to install JBOSS EAP XP 2.0.0. See https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.3/pdf/using_eclipse_microprofile_with_jboss_eap_xp_2.0.0/Red_Hat_JBoss_Enterprise_Application_Platform-7.3-Using_Eclipse_MicroProfile_with_JBoss_EAP_XP_2.0.0-en-US.pdf
No comments:
Post a Comment