-
|
Is define security scheme as mutualTLS supported? |
Beta Was this translation helpful? Give feedback.
Answered by
vearutop
Feb 24, 2025
Replies: 1 comment 1 reply
-
|
Mutual TLS is supported by OpenAPI 3.1, and by this library too. Please check an example below: reflector := openapi31.Reflector{}
securityName := "mTLS-example"
// Declare security scheme.
reflector.SpecEns().ComponentsEns().WithSecuritySchemesItem(
securityName,
openapi31.SecuritySchemeOrReference{
SecurityScheme: (&openapi31.SecurityScheme{MutualTLS: &openapi31.MutualTLS{}}).
WithDescription("My mutual TLS security."),
},
)
oc, err := reflector.NewOperationContext(http.MethodGet, "/secure")
require.NoError(t, err)
oc.AddRespStructure(struct {
Secret string `json:"secret"`
}{})
// Add security requirement to operation.
oc.AddSecurity(securityName)
// Add operation to schema.
require.NoError(t, reflector.AddOperation(oc))Here is how resulting schema looks like: assertjson.EqMarshal(t, `{
"openapi":"3.1.0","info":{"title":"","version":""},
"paths":{
"/secure":{
"get":{
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{
"schema":{"properties":{"secret":{"type":"string"}},"type":"object"}
}
}
}
},
"security":[{"mTLS-example":[]}]
}
}
},
"components":{
"securitySchemes":{
"mTLS-example":{"description":"My mutual TLS security.","type":"mutualTLS"}
}
}
}`, reflector.SpecSchema()) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yuanhh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mutual TLS is supported by OpenAPI 3.1, and by this library too. Please check an example below: