swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
374 stars 17 forks source link

How to generate openapi.json file only? #189

Closed futugyou closed 9 months ago

futugyou commented 9 months ago

How to generate openapi.json file without using http.ListenAndServe to start the service. I just want to use 'go run .' to generate an openapi.json file, not start a http service.

vearutop commented 9 months ago

You can do it with a function like this.

func DumpOpenAPISpec(fn string, s *web.Service) error {
    j, err := json.Marshal(s.OpenAPISchema())
    if err != nil {
        return err
    }

    return os.WriteFile(fn, j, 0600)
}
futugyou commented 9 months ago

You can do it with a function like this.

func DumpOpenAPISpec(fn string, s *web.Service) error {
  j, err := json.Marshal(s.OpenAPISchema())
  if err != nil {
      return err
  }

  return os.WriteFile(fn, j, 0600)
}

thank you for your help