From 7b9f57125ea383c89bc00b98459e04541f37a42a Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Fri, 2 Aug 2024 10:31:51 +0200 Subject: [PATCH] feat(trait): drop support for swagger Closes #5735 --- pkg/apis/camel/v1/trait/openapi.go | 2 +- pkg/trait/openapi_test.go | 161 ++++++++++++++++++++--------- 2 files changed, 114 insertions(+), 49 deletions(-) diff --git a/pkg/apis/camel/v1/trait/openapi.go b/pkg/apis/camel/v1/trait/openapi.go index 3a28b3f37c..a8c7f6a41f 100644 --- a/pkg/apis/camel/v1/trait/openapi.go +++ b/pkg/apis/camel/v1/trait/openapi.go @@ -22,6 +22,6 @@ package trait // +camel-k:trait=openapi. type OpenAPITrait struct { PlatformBaseTrait `property:",squash" json:",inline"` - // The configmaps holding the spec of the OpenAPI + // The configmaps holding the spec of the OpenAPI (compatible with > 3.0 spec only). Configmaps []string `property:"configmaps" json:"configmaps,omitempty"` } diff --git a/pkg/trait/openapi_test.go b/pkg/trait/openapi_test.go index 6329e188ad..8ef68f2a27 100644 --- a/pkg/trait/openapi_test.go +++ b/pkg/trait/openapi_test.go @@ -110,52 +110,117 @@ func TestRestDslTraitApplyError(t *testing.T) { } var openapi = ` -{ - "swagger" : "2.0", - "info" : { - "version" : "1.0", - "title" : "Greeting REST API" - }, - "host" : "", - "basePath" : "/camel/", - "tags" : [ { - "name" : "greetings", - "description" : "Greeting to {name}" - } ], - "schemes" : [ "http" ], - "paths" : { - "/greetings/{name}" : { - "get" : { - "tags" : [ "greetings" ], - "operationId" : "greeting-api", - "parameters" : [ { - "name" : "name", - "in" : "path", - "required" : true, - "type" : "string" - } ], - "responses" : { - "200" : { - "description" : "Output type", - "schema" : { - "$ref" : "#/definitions/Greetings" - } - } - } - } - } - }, - "definitions" : { - "Greetings" : { - "type" : "object", - "properties" : { - "greetings" : { - "type" : "string" - } - } - } - } -} +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: http://petstore.swagger.io/v1 +paths: + /pets: + get: + summary: List all pets + operationId: listPets + tags: + - pets + parameters: + - name: limit + in: query + description: How many items to return at one time (max 100) + required: false + schema: + type: integer + format: int32 + responses: + '200': + description: A paged array of pets + headers: + x-next: + description: A link to the next page of responses + schema: + type: string + content: + application/json: + schema: + $ref: "#/components/schemas/Pets" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + summary: Create a pet + operationId: createPets + tags: + - pets + responses: + '201': + description: Null response + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /pets/{petId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: petId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string ` func TestRestDslTraitApplyWorks(t *testing.T) { @@ -176,7 +241,7 @@ func TestRestDslTraitApplyWorks(t *testing.T) { Namespace: "default", }, Data: map[string]string{ - "greetings-api.json": openapi, + "pets.yaml": openapi, }, }, cm, @@ -254,5 +319,5 @@ func TestRestDslTraitApplyWorks(t *testing.T) { return cm.Name == "hello-openapi-000" }) assert.NotNil(t, sourceCm) - assert.Contains(t, sourceCm.Data["content"], "get id=\"greeting-api\" path=\"/greetings/{name}") + assert.Contains(t, sourceCm.Data["content"], "get id=\"showPetById\" path=\"/pets/{petId}\"") }