diff --git a/src/main/scala/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.scala b/src/main/scala/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.scala index 92589f86..a4129511 100644 --- a/src/main/scala/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.scala +++ b/src/main/scala/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.scala @@ -48,15 +48,19 @@ class Swagger2dot0Json private(apiInfo: ApiInfo) extends Renderer { } def apply(mr: Seq[ModuleRoute]): JsonRootNode = { - val paths = mr + val pathFields: List[Field] = mr .groupBy(_.toString) - .map { case (path, routes) => path -> obj(routes.map(a => render(a)._1))}.toSeq + .foldLeft((List[Field](), List[Field]())) { + case ((memoFields, memoDefinitions), (path, routes)) => + val field: Field = path -> obj(routes.map(a => render(a)._1)) + (field :: memoFields, memoDefinitions) + }._1 obj( "swagger" -> string("2.0"), "info" -> render(apiInfo), "basePath" -> string("/"), - "paths" -> obj(paths), + "paths" -> obj(pathFields), "definitions" -> obj() ) } diff --git a/src/test/resources/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.json b/src/test/resources/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.json index 2e22a80e..cf8b3849 100644 --- a/src/test/resources/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.json +++ b/src/test/resources/io/github/daviddenton/fintrospect/renderers/Swagger2dot0Json.json @@ -7,6 +7,50 @@ }, "basePath": "/", "paths": { + "/basepath/welcome/{firstName}/bertrand/{secondName}": { + "get": { + "tags": [ + "/basepath" + ], + "summary": null, + "produces": [], + "consumes": [], + "parameters": [ + { + "in": "query", + "name": "query", + "description": "description of the query", + "required": true, + "type": "boolean" + }, + { + "in": "path", + "name": "firstName", + "description": null, + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "bertrand", + "description": null, + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "secondName", + "description": null, + "required": true, + "type": "string" + } + ], + "responses": {}, + "security": [ + {} + ] + } + }, "/basepath/echo/{message}": { "post": { "tags": [ @@ -80,51 +124,7 @@ {} ] } - }, - "/basepath/welcome/{firstName}/bertrand/{secondName}": { - "get": { - "tags": [ - "/basepath" - ], - "summary": null, - "produces": [], - "consumes": [], - "parameters": [ - { - "in": "query", - "name": "query", - "description": "description of the query", - "required": true, - "type": "boolean" - }, - { - "in": "path", - "name": "firstName", - "description": null, - "required": true, - "type": "string" - }, - { - "in": "path", - "name": "bertrand", - "description": null, - "required": true, - "type": "string" - }, - { - "in": "path", - "name": "secondName", - "description": null, - "required": true, - "type": "string" - } - ], - "responses": {}, - "security": [ - {} - ] - } } }, "definitions": {} -} \ No newline at end of file +}