Skip to content

Commit

Permalink
feat(trait): drop support for swagger
Browse files Browse the repository at this point in the history
Closes #5735
  • Loading branch information
squakez committed Aug 2, 2024
1 parent 083a8c9 commit 471cc9c
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/camel/v1/trait/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
161 changes: 113 additions & 48 deletions pkg/trait/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -176,7 +241,7 @@ func TestRestDslTraitApplyWorks(t *testing.T) {
Namespace: "default",
},
Data: map[string]string{
"greetings-api.json": openapi,
"pets.yaml": openapi,
},
},
cm,
Expand Down Expand Up @@ -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}\"")
}

0 comments on commit 471cc9c

Please sign in to comment.