Coder Social home page Coder Social logo

Comments (1)

bbattah avatar bbattah commented on June 18, 2024 1

Agreed. I have just begun playing with Saunter and ran into the same challenge.

Ideally I would like to easily include a "Swashbuckle" style endpoint with an HTML UI.
However, in the mean-time I can settle for generating a static html file I can commit with the application source.

En-route to this I am writing test code that uses Saunter to scan a specific assembly for relevant message formats and plug them into a "Skeleton" AsyncApiDocument. Then the json\yaml must be serialized in order to feed the standard generator with html template.

I had to lift exactly the same code as above into my own project to get this close to working.
Additionally, the serialization needs to ensure proper lower-casing of the serialized asyncapi.json document AND ensure that the asyncapi attribute is tagged with a proper version value.
Relevant code snippets here:

private static void ConvertToHtml(AsyncApiDocument doc)
        {
            string json = AsyncApiDocToString(doc);

            File.WriteAllText("asyncapi.json", json);

            using (Process compiler = new Process())
            {
                compiler.StartInfo.FileName = "ag";
                compiler.StartInfo.Arguments = $" asyncapi.json @asyncapi/html-template -o output --force-write --param singleFile=true";
                compiler.StartInfo.UseShellExecute = true;
                compiler.StartInfo.RedirectStandardOutput = false;
                compiler.Start();
                compiler.WaitForExit();
            }
        }
        
        private static string AsyncApiDocToString(AsyncApiDocument doc)
        {
            string docString = JsonSerializer.Serialize(
                doc,
                new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    WriteIndented = true,
                    IgnoreNullValues = true,
                    Converters =
                    {
                        new DictionaryKeyToStringConverter(),
                        new InterfaceImplementationConverter(),
                    },
                }
            );

            return docString.Replace("\"asyncApi\": 0,", "\"asyncapi\": \"2.0.0\",");
        }

Please consider this an "up-vote" for the suggested solution and related issues.

from saunter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.