Swashbuckle.aspnetcore: Swashbuckle 5.0.0 "The provided definition does not specify a valid version field" even when valid.

Created on 16 Jul 2019  路  7Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

I am using Swashbuckle.AspnetCore (4.0.1) and get an error only on our webserver...localhost runs fine.

Unable to render this definition
The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).

I thought it was related to jwt authentication (configured but not active) and was going to try the above, but I am unable set the the SwaggerDoc( "v1" , Info parameter to new OpenApiInfo , I get a parameter mismatch compile error...thought someone might know what I am doing wrong...thanks in advance.

I'm experiencing an identical issue, but I'm actually using OpenApiInfo as a parameter and argument.

In fact my json begins like this:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Personal Site Api",
    "version": "v1"
  }, 
... 
},

_reference @yehudamakarov in https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1099#issuecomment-511654032_

--

Most helpful comment

I fixed it for myself by adding a rule to the routing configuration used by my server.
Since it is ingress-nginx in a cluster, I added the following. (Keep in mind, if you were to go to /api/values, the c# code would receive the request as /values. Since the index.html was requesting /swagger/v1/swagger.json, the request was not actually going to the c# API, but rather to my front end catching anything not beginning with /api. Now I have to catch anything beginning with /swagger and send that to the API without rewriting the request path.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - <site name>
        - www.<site name>
      secretName: <certificate name>
  rules:
    - host: <site name>
      http:
        paths:
          - path: /(swagger/?.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /api/?(.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /?(.*)
            backend:
              serviceName: client-service
              servicePort: 3000

    - host: www.<site name>
      http:
        paths:
          - path: /(swagger/?.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /api/?(.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /?(.*)
            backend:
              serviceName: client-service
              servicePort: 3000

All 7 comments

Screen Shot 2019-07-16 at 00 36 01

The url inside the configObject is a problem. the api is behind the root /api. the index.html requested the JS files from /api... but this piece of JSON for the url key in . configObject is not.

I fixed it for myself by adding a rule to the routing configuration used by my server.
Since it is ingress-nginx in a cluster, I added the following. (Keep in mind, if you were to go to /api/values, the c# code would receive the request as /values. Since the index.html was requesting /swagger/v1/swagger.json, the request was not actually going to the c# API, but rather to my front end catching anything not beginning with /api. Now I have to catch anything beginning with /swagger and send that to the API without rewriting the request path.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - <site name>
        - www.<site name>
      secretName: <certificate name>
  rules:
    - host: <site name>
      http:
        paths:
          - path: /(swagger/?.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /api/?(.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /?(.*)
            backend:
              serviceName: client-service
              servicePort: 3000

    - host: www.<site name>
      http:
        paths:
          - path: /(swagger/?.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /api/?(.*)
            backend:
              serviceName: api-service 
              servicePort: 5000
          - path: /?(.*)
            backend:
              serviceName: client-service
              servicePort: 3000

This is a non issue and there just needs to be some customization set up for where the JSON is served from and where to look for it. Will close with accompanying code soon.

This feels unrelated to Swashbuckle

If unrelated means not the fault of, that is correct.

But nonetheless it was a problem experienced while setting up the tool. So I provided the question and answer here.

We had the same issue, thanks for posting your fix.

In a standalone web server the configuration this fix looks like this:
Nginx config:
...........
location /api/ {
proxy_pass http://IP-where-api-is-running:PORT;
}
location /swagger/ {
proxy_pass http://IP-where-api-is-running:PORT;
}
.............

Was this page helpful?
0 / 5 - 0 ratings