Skip to content

Non-deterministic ordering SecurityDefinitions #316

@neglect-yp

Description

@neglect-yp

#311 (comment)

Summary

Currently the order of SecurityDefinitions is not deterministic. SecurityDefinitions is used in below templates.

Reproduction

test.yaml

openapi: 3.0.2
paths:
  /a:
    get:
      oparationId: a
      security:
        - ApiId: []
          ApiKey: []

components:
  ApiId:
    type: apiKey
    in: header
    name: X-Api-Id
  ApiKey:
    type: apiKey
    in: header
    name: X-Api-Key
$ diff -u <(go run ./cmd/oapi-codegen/ test.yaml) <(go run ./cmd/oapi-codegen/ test.yaml)
--- /dev/fd/11	2021-03-17 13:02:42.000000000 +0900
+++ /dev/fd/12	2021-03-17 13:02:42.000000000 +0900
@@ -251,10 +251,10 @@
 func (w *ServerInterfaceWrapper) GetA(ctx echo.Context) error {
 	var err error

-	ctx.Set(ApiKeyScopes, []string{""})
-
 	ctx.Set(ApiIdScopes, []string{""})

+	ctx.Set(ApiKeyScopes, []string{""})
+
 	// Invoke the callback with all the unmarshalled arguments
 	err = w.Handler.GetA(ctx)
 	return err

This problem happens randomly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions