SwaggerEditor

   1 docker pull docker.swagger.io/swaggerapi/swagger-editor
   2 docker run --rm --name swagger-editor -d -p 8181:8080 docker.swagger.io/swaggerapi/swagger-editor
   3 docker ps 
   4 curl localhost:8181

Example of OpenAPI/Swagger data contract

   1 openapi: 3.0.4
   2 info:
   3   title: Swagger User - OpenAPI 3.0
   4   description: |-
   5     This is a sample user Server based on the OpenAPI 3.0 specification.
   6 
   7     Some useful links:
   8     - [Google](https://www.google.com)
   9   termsOfService: https://swagger.io/terms/
  10   contact:
  11     email: apiteam@example.org
  12   license:
  13     name: License Apache 2.0
  14     url: https://www.apache.org/licenses/LICENSE-2.0.html
  15   version: 1.0.12
  16 externalDocs:
  17   description: Find out more about Swagger
  18   url: https://swagger.io
  19 servers:
  20   - url: http://localhost:8181/api/v3
  21 tags:
  22   - name: user
  23     description: Operations about user
  24 paths:
  25   /user/createWithList:
  26     post:
  27       tags:
  28         - user
  29       summary: Creates list of users with given input array.
  30       description: Creates list of users with given input array.
  31       operationId: createUsersWithListInput
  32       requestBody:
  33         content:
  34           application/json:
  35             schema:
  36               type: array
  37               items:
  38                 $ref: '#/components/schemas/User'
  39       responses:
  40         '200':
  41           description: Successful operation
  42           content:
  43             application/json:
  44               schema:
  45                 $ref: '#/components/schemas/User'
  46         default:
  47           description: Unexpected error
  48           content:
  49             application/json:
  50               schema:
  51                 $ref: "#/components/schemas/Error"
  52   /user/login:
  53     get:
  54       tags:
  55         - user
  56       summary: Logs user into the system.
  57       description: Log into the system.
  58       operationId: loginUser
  59       parameters:
  60         - name: username
  61           in: query
  62           description: The user name for login
  63           required: true
  64           schema:
  65             type: string
  66         - name: password
  67           in: query
  68           description: The password for login in clear text
  69           required: true
  70           schema:
  71             type: string
  72       responses:
  73         '200':
  74           description: successful operation
  75           headers:
  76             X-Rate-Limit:
  77               description: calls per hour allowed by the user
  78               schema:
  79                 type: integer
  80                 format: int32
  81             X-Expires-After:
  82               description: date in UTC when token expires
  83               schema:
  84                 type: string
  85                 format: date-time
  86           content:
  87             application/json:
  88               schema:
  89                 type: string
  90         '400':
  91           description: Invalid username/password supplied
  92         default:
  93           description: Unexpected error
  94           content:
  95             application/json:
  96               schema:
  97                 $ref: "#/components/schemas/Error"
  98   /user/logout:
  99     get:
 100       tags:
 101         - user
 102       summary: Logs out current logged in user session.
 103       description: Log user out of the system.
 104       operationId: logoutUser
 105       parameters: []
 106       responses:
 107         '200':
 108           description: successful operation
 109         default:
 110           description: Unexpected error
 111           content:
 112             application/json:
 113               schema:
 114                 $ref: "#/components/schemas/Error"
 115   /user/{username}:
 116     get:
 117       tags:
 118         - user
 119       summary: Get user by user name.
 120       description: Get user detail based on username.
 121       operationId: getUserByName
 122       parameters:
 123         - name: username
 124           in: path
 125           description: The name that needs to be fetched. Use user1 for testing
 126           required: true
 127           schema:
 128             type: string
 129       responses:
 130         '200':
 131           description: successful operation
 132           content:
 133             application/json:
 134               schema:
 135                 $ref: '#/components/schemas/User'
 136         '400':
 137           description: Invalid username supplied
 138         '404':
 139           description: User not found
 140         default:
 141           description: Unexpected error
 142           content:
 143             application/json:
 144               schema:
 145                 $ref: "#/components/schemas/Error"
 146     put:
 147       tags:
 148         - user
 149       summary: Update user resource.
 150       description: This can only be done by the logged in user.
 151       operationId: updateUser
 152       parameters:
 153         - name: username
 154           in: path
 155           description: name that need to be updated
 156           required: true
 157           schema:
 158             type: string
 159       requestBody:
 160         description: Update an existent user in the store
 161         content:
 162           application/json:
 163             schema:
 164               $ref: '#/components/schemas/User'
 165       responses:
 166         '200':
 167           description: successful operation
 168         '400':
 169           description: bad request
 170         '404':
 171           description: user not found
 172         default:
 173           description: Unexpected error
 174           content:
 175             application/json:
 176               schema:
 177                 $ref: "#/components/schemas/Error"
 178     delete:
 179       tags:
 180         - user
 181       summary: Delete user resource.
 182       description: This can only be done by the logged in user.
 183       operationId: deleteUser
 184       parameters:
 185         - name: username
 186           in: path
 187           description: The name that needs to be deleted
 188           required: true
 189           schema:
 190             type: string
 191       responses:
 192         '200':
 193           description: User deleted
 194         '400':
 195           description: Invalid username supplied
 196         '404':
 197           description: User not found
 198         default:
 199           description: Unexpected error
 200           content:
 201             application/json:
 202               schema:
 203                 $ref: "#/components/schemas/Error"
 204 components:
 205   schemas:
 206     User:
 207       type: object
 208       properties:
 209         id:
 210           type: integer
 211           format: int64
 212           example: 10
 213         username:
 214           type: string
 215           example: theUser
 216         firstName:
 217           type: string
 218           example: John
 219         lastName:
 220           type: string
 221           example: James
 222         email:
 223           type: string
 224           example: john@email.com
 225         password:
 226           type: string
 227           example: '12345'
 228         phone:
 229           type: string
 230           example: '12345'
 231         userStatus:
 232           type: integer
 233           description: User Status
 234           format: int32
 235           example: 1
 236       xml:
 237         name: user
 238     Error:
 239       type: object
 240       properties:
 241         code:
 242           type: string
 243         message:
 244           type: string
 245       required:
 246         - code
 247         - message
 248   requestBodies:
 249     UserArray:
 250       description: List of user object
 251       content:
 252         application/json:
 253           schema:
 254             type: array
 255             items:
 256               $ref: '#/components/schemas/User'

   1 cd ~/Downloads
   2 mkdir -p spring-server-generated
   3 mv spring-server-generated.zip spring-server-generated/
   4 cd  spring-server-generated/
   5 unzip spring-server-generated.zip 
   6 mvn clean install 
   7 SERVER_PORT=8282 java -jar target/swagger-spring-1.0.0.jar

Gemini prompt

Generate an OpenAPI data contract in YAML format that returns hello concatenated with a parameter to field message inside an object when calling endpoint hello

   1 openapi: 3.0.0
   2 info:
   3   title: Hello Parameterized API
   4   version: v1
   5 
   6 servers:
   7   - url: http://localhost:8080/ # Replace with your actual server URL
   8 
   9 paths:
  10   /hello:
  11     get:
  12       summary: Returns "Hello, " concatenated with a provided parameter in a message field.
  13       parameters:
  14         - in: query
  15           name: name
  16           schema:
  17             type: string
  18           description: The name to say hello to.
  19       responses:
  20         '200':
  21           description: Successful response
  22           content:
  23             application/json:
  24               schema:
  25                 type: object
  26                 properties:
  27                   message:
  28                     type: string
  29                     example: Hello, World!
  30               examples:
  31                 default:
  32                   value:
  33                     message: Hello, World!

Copilot prompt

Generate an OpenAPI data contract in YAML format that returns hello concatenated with a parameter to field message inside an object when calling endpoint hello

   1 openapi: 3.0.3
   2 info:
   3   title: Hello API
   4   version: "1.0.0"
   5 paths:
   6   /hello:
   7     get:
   8       summary: Returns a message
   9       parameters:
  10         - name: name
  11           in: query
  12           description: The parameter to concatenate with "hello"
  13           required: true
  14           schema:
  15             type: string
  16       responses:
  17         '200':
  18           description: A successful response
  19           content:
  20             application/json:
  21               schema:
  22                 type: object
  23                 properties:
  24                   message:
  25                     type: string
  26                     example: hello, John

Grok prompt

Generate an OpenAPI data contract in YAML format that returns hello concatenated with a parameter to field message inside an object when calling endpoint hello

   1 openapi: 3.0.3
   2 info:
   3   title: Hello API
   4   version: 1.0.0
   5   description: A simple API that concatenates 'hello' with a parameter
   6 paths:
   7   /hello:
   8     get:
   9       summary: Get hello message
  10       description: Returns an object with a message field containing 'hello' concatenated with the provided name parameter
  11       operationId: getHelloMessage
  12       parameters:
  13         - name: name
  14           in: query
  15           required: true
  16           schema:
  17             type: string
  18           description: The name to concatenate with 'hello'
  19       responses:
  20         '200':
  21           description: Successful response
  22           content:
  23             application/json:
  24               schema:
  25                 type: object
  26                 properties:
  27                   message:
  28                     type: string
  29                     description: The concatenated message
  30                 required:
  31                   - message
  32                 example:
  33                   message: hello John
  34         '400':
  35           description: Bad request, missing or invalid parameter
  36           content:
  37             application/json:
  38               schema:
  39                 type: object
  40                 properties:
  41                   error:
  42                     type: string
  43                     description: Error message
  44                 required:
  45                   - error
  46               example:
  47                 error: 'name parameter is required'
  48 components: {}

ChatGPT prompt

Generate an OpenAPI data contract in YAML format that returns hello concatenated with a parameter to field message inside an object when calling endpoint hello

   1 openapi: 3.0.3
   2 info:
   3   title: Hello API
   4   version: 1.0.0
   5 paths:
   6   /hello:
   7     get:
   8       summary: Returns a greeting message
   9       parameters:
  10         - in: query
  11           name: name
  12           schema:
  13             type: string
  14           required: true
  15           description: Name to be included in the greeting
  16       responses:
  17         '200':
  18           description: Greeting response
  19           content:
  20             application/json:
  21               schema:
  22                 type: object
  23                 properties:
  24                   message:
  25                     type: string
  26                     example: hello John

SwaggerEditor (last edited 2025-04-11 18:29:14 by vitor)