Skip to content

Support loading via http.FileSystem #311

@hottestseason

Description

@hottestseason

It is great if this library can load with http.FileSystem because we can embed specification files into single binary with Go1.16's embed feature

package main

import (
	"embed"
	"log"
	"net/http"

	"github.com/getkin/kin-openapi/openapi3"
)

//go:embed spec/*
var spec embed.FS

func main() {
	loader := openapi3.NewSwaggerLoader()
	loader.IsExternalRefsAllowed = true

	swagger, err := loader.LoadSwaggerFromFileSystem(http.FS(spec), "spec/openapi.yml")
	if err != nil {
		panic(err)
	}

	log.Printf("%s\n", swagger.Paths["/foo"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["foo"].Value.Type)
}
openapi: "3.0.0"
info:
  version: "1.0"
  title: example
paths:
  /foo:
    $ref: ./paths/foo.yml
get:
  parameters:
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
            properties:
              foo:
                type: string
                example: foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions