Getting APIDefinition JSON in middleware

Currently i am creating a middleware to AUTH scopes being passed in from the meta data of an API Definition. Using s.TykMiddleware.Spec.APIDefinition.RawData gives a map[string]interface{} value back. Is there a way to just call the APIDefinition and get the actual json?

Hi, APIDefinition doesn’t store the actual JSON, but it could be useful in some cases like the one you describe.

At the moment I suggest using json.Marshal:

// If you want to use it as []byte:
jsonBytes, _ := json.Marshal(s.TykMiddleware.Spec.APIDefinition.RawData)
// If you want to use it as string:
jsonStr := string(jsonBytes)

You could perform this on middleware initialization and then keep the data around, when a request comes.