Code Monkey home page Code Monkey logo

Comments (5)

thesamet avatar thesamet commented on June 4, 2024

Hi @Joshua-Scurr ,
I read the write up a few times and trying to make sure I understand the problem you are trying to solve. Here's what I got: you generate an OpenAPI JSON file using your own protoc plugin, and you want the generated file to include a version number that is avaialable as a value in SBT. It is possible to pass custom parameters to protoc plugins through sbt-protoc. If you follow writing custom plugins look for request.parameters to see how these can become available in your code generator.

from scalapb.

Joshua-Scurr avatar Joshua-Scurr commented on June 4, 2024

That sounds correct; thank you - I will have a look at that this morning

from scalapb.

regiskuckaertz avatar regiskuckaertz commented on June 4, 2024

@thesamet it looks like indeed this is turned into a closed vocabulary of parameters, here:

def fromStringCollectUnrecognized(
params: String
): Either[String, (GeneratorParams, Seq[String])] = {
params
.split(",")
.map(_.trim)
.filter(_.nonEmpty)
.foldLeft[Either[String, (GeneratorParams, Seq[String])]](
Right((GeneratorParams(), Seq.empty))
) {
case (Right((params, unrecognized)), str) =>
str match {
case "java_conversions" => Right((params.copy(javaConversions = true), unrecognized))
case "flat_package" => Right((params.copy(flatPackage = true), unrecognized))
case "grpc" => Right((params.copy(grpc = true), unrecognized))
case "single_line_to_proto_string" =>
Right((params.copy(singleLineToProtoString = true), unrecognized))
case "ascii_format_to_string" =>
Right((params.copy(asciiFormatToString = true), unrecognized))
case "no_lenses" => Right((params.copy(lenses = false), unrecognized))
case "retain_source_code_info" =>
Right((params.copy(retainSourceCodeInfo = true), unrecognized))
case p => Right((params, unrecognized :+ p))
}
case (l, _) => l
}
}

do you think we could change GeneratorParams to:

case class GeneratorParams(
    javaConversions: Boolean = false,
    flatPackage: Boolean = false,
    grpc: Boolean = false,
    singleLineToProtoString: Boolean = false,
    asciiFormatToString: Boolean = false,
    lenses: Boolean = true,
    retainSourceCodeInfo: Boolean = false,
    customOptions: List[String] = Nil
)

... then all the unrecognized options end up in customOptions and do not generate an error?

from scalapb.

thesamet avatar thesamet commented on June 4, 2024

The success type of fromStringCollectUnrecognized is a (GeneratorParams, Seq[String]). The Seq[String] represents all the options that are not ScalaPB options, for third-party code generators to process further.

from scalapb.

Joshua-Scurr avatar Joshua-Scurr commented on June 4, 2024

That looks to have been the answer. Many thanks!
EDIT: Confirming this worked for us. Closing the issue.

from scalapb.

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.