Ejemplo n.º 1
0
    public void GenerateAssets(OpenApiDocument doc)
    {
        string assetsPath = EditorUtility.OpenFolderPanel("Select assets folder", _lastAssetPath, "");

        _lastAssetPath = assetsPath;
        assetsPath     = assetsPath.Substring(assetsPath.IndexOf("Assets"));
        ApiAsset apiAsset = AssetsHelper.GetOrCreateScriptableObject <ApiAsset>(assetsPath, doc.Info.Title);

        #region ApiAsset update
        apiAsset.info = new OAInfo()
        {
            Title          = doc.Info.Title,
            Description    = doc.Info.Description,
            Version        = doc.Info.Version,
            TermsOfService = doc.Info.TermsOfService == null ? "" : doc.Info.TermsOfService.ToString(),
            Contact        = CreateContact(doc.Info.Contact),
            License        = CreateLicence(doc.Info.License),
        };

        apiAsset.externalDocs = CreateExternalDocs(doc.ExternalDocs);

        apiAsset.servers = doc.Servers.Select(s => CreateAOServer(s)).ToList();


        apiAsset.pathItemAssets = new List <PathItemAsset>();

        #endregion

        foreach (var p in doc.Paths)
        {
            string        fileName = p.Key.Replace('/', '_');
            PathItemAsset a        = AssetsHelper.GetOrCreateScriptableObject <PathItemAsset>(assetsPath, fileName);
            a.ApiAsset = apiAsset;

            #region path item update


            a.Path = p.Key;

            a.Summary     = p.Value.Summary;
            a.Description = p.Value.Description;
            a.Parameters  = p.Value.Parameters.Select(par => CreateAOParameter(par)).ToList();
            a.Operations  = p.Value.Operations.Select(o => CreateAOOperation(o.Key, o.Value, a)).ToList();
            a.Servers     = p.Value.Servers.Select(s => CreateAOServer(s)).ToList();

            #endregion

            apiAsset.pathItemAssets.Add(a);
        }



        AssetDatabase.SaveAssets();
    }
Ejemplo n.º 2
0
    private OAOperation CreateAOOperation(OperationType operationType, OpenApiOperation op, PathItemAsset pathItemAsset)
    {
        var operation = new OAOperation()
        {
            pathAsset     = pathItemAsset,
            OperationId   = op.OperationId,
            OperationType = (AOOperationType)operationType,
            Summary       = op.Summary,
            Description   = op.Description,
            Deprecated    = op.Deprecated,

            Parameters = op.Parameters.Count > 0 ?
                         op.Parameters.Select(p => CreateAOParameter(p)).ToList() :
                         pathItemAsset.Parameters,


            Servers = op.Servers.Select(s => CreateAOServer(s)).ToList(),

            Tags = op.Tags.Select(t => CreateOATag(t)).ToList(),

            RequestBody = CreateOARequestBody(op.RequestBody),

            ExternalDocs = CreateExternalDocs(op.ExternalDocs),
        };

        operation.ParametersValues = operation.Parameters.Select(p => new ParameterValue {
            parameter = p
        }).ToList();

        return(operation);
    }